nisha rayte

nisha rayte

  • NA
  • 35
  • 16.3k

Passing Values between user Controls in Silverlight Appplication

Jun 14 2012 2:53 AM

I am created silverlight application ,in that application two user control in 1st usercontrol i put combobox and as per selected that combobox value bind chart in another usercontrol . i am try pass that combo box value to another usercontrol .follow my two user control code

1) combobox.xaml


<UserControl x:Class="dashboard.combobox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:ee="http://schemas.microsoft.com/expression/2010/effects"
    mc:Ignorable="d"
              xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    d:DesignHeight="300" d:DesignWidth="400" >
  <Grid x:Name="Root">
        <ComboBox Margin="0,6,0,0" VerticalAlignment="Top" Style="{StaticResource ComboBoxStyle1}" Foreground="#FF070E14" Opacity="0.5" Width="140" SelectedItem="Selct" SelectionChanged="ComboBox_SelectionChanged" x:Name="element">
            <ComboBox.Background>
             <ImageBrush Stretch="Fill"/>
             </ComboBox.Background>
            <ComboBox.BorderBrush>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF263947" Offset="1"/>
                </LinearGradientBrush>
            </ComboBox.BorderBrush>
            <ComboBoxItem Content="TypeOfSolution" Foreground="#FF272727"  />
            <ComboBoxItem Content="Solution" Foreground="#FF272727" />
            <ComboBoxItem Content="Dealer" Foreground="#FF272727" />

        </ComboBox>
    </Grid>
</UserControl>


 

 

2)ChartUserControl.xaml

<UserControl x:Class="dashboard.ChartUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
             xmlns:telerikCharting="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
 x:Name="parent"
    mc:Ignorable="d" >
 
 <UserControl.Resources>
  <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
  <telerik:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" />
 </UserControl.Resources>
 
 <Grid x:Name="root">
      <telerikChart:RadChart x:Name="radChart" Style="{StaticResource RadChartStyle}" Background="Transparent"  BorderThickness="0"
   Foreground="{StaticResource text}" AxisForeground="{StaticResource text}"  FontFamily="Segoe UI Light" Width="400" Margin="0,0,0,0">
          
        </telerikChart:RadChart>

 

 
 </Grid>
</UserControl>
ChartUserControl.xaml.cs

  public ChartUserControl()
        {
            InitializeComponent();
         
            radChart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed;
            PieSeriesDefinition piechart = new PieSeriesDefinition();
            radChart.DefaultSeriesDefinition = piechart;
            MainViewModel mvm = new MainViewModel();
            DataContext = mvm;
            radChart.ItemsSource = mvm.customers;
        }


here  MainViewModel  code


 public class MainViewModel
    {

           private Service1Client client;

           public MainViewModel()
           {
               client = new Service1Client();
               client.TypeSolutionAsync();
               client.GetGridDetailAsync();
               client.SolutionAsync();
               client.GetGridDetailCompleted += new EventHandler<GetGridDetailCompletedEventArgs>(client_GetGridDetailCompleted);
               client.SolutionCompleted += new EventHandler<SolutionCompletedEventArgs>(client_SolutionCompleted);
               this.solution = new ObservableCollection<SolutionData>();
               this.customers = new ObservableCollection<displaydata>();
               this.Gridobjects = new ObservableCollection<GridData>();
               client.TypeSolutionCompleted += new EventHandler<TypeSolutionCompletedEventArgs>(client_TypeSolutionCompleted);
           }
           public void client_TypeSolutionCompleted(object o, TypeSolutionCompletedEventArgs e)
           {
               if (e.Error == null && e.Result != null)
               {
                   foreach (displaydata c in e.Result)
                   {
                       this.customers.Add(c);
                   }
               }
           }
           public void client_GetGridDetailCompleted(object o, GetGridDetailCompletedEventArgs e)
           {
               if (e.Error == null && e.Result != null)
               {
                   foreach (GridData c in e.Result)
                   {
                       this.Gridobjects.Add(c);
                   }
               }

           }
        public void client_SolutionCompleted(object o, SolutionCompletedEventArgs e)
           {
               if (e.Error == null && e.Result != null)
               {
                   foreach (SolutionData c in e.Result)
                   {
                       this.solution.Add(c);

                   }
               }
           }


           public ObservableCollection<displaydata> customers
           {
               get;
               set;
           }
           public ObservableCollection<GridData> Gridobjects
           {
               get;
               set;

           }
        public ObservableCollection<SolutionData> solution
           {
               get;
               set;
           }
    }


please help to solve this problem


Answers (2)