I have a kind of annoying scenario here.
In my WPF GUI I declared some RadioButtons, I want the right one to be checked when the GUI loads.
XAML:
<RadioButton Grid.Row="0" Grid.Column="0" Name="RadioButtonShowSettings" GroupName="OnTrayClick" Content="Show settings window" HorizontalAlignment="Left" VerticalAlignment="Center" />
<RadioButton Grid.Row="1" Grid.Column="0" Name="RadioButtonOpenFile" GroupName="OnTrayClick" Content="Open upload dialog" HorizontalAlignment="Left" VerticalAlignment="Center" />
<RadioButton Grid.Row="2" Grid.Column="0" Name="RadioButtonIndexFile" GroupName="OnTrayClick" Content="Open file indexer" HorizontalAlignment="Left" VerticalAlignment="Center" />
<RadioButton Grid.Row="0" Grid.Column="1" Name="RadioButtonImageGallery" GroupName="OnTrayClick" Content="Open image gallery" HorizontalAlignment="Left" VerticalAlignment="Center" />
<RadioButton Grid.Row="1" Grid.Column="1" Name="RadioButtonTakeScreenshot" GroupName="OnTrayClick" Content="Take a screenshot (3 seconds delay)" HorizontalAlignment="Left" VerticalAlignment="Center" />
To keep possible bugs to a minimum I created a Property in my HonkySettings of the type String called TrayIconBehaviour. It contains the ContentProperty of the currently checked RadioButton.
I've been doing the loading programatically with a LoadSettings() function, but I'd like to remove that and do something more appealing with Bindings.
LoadSettings:
private void LoadSettings()
{
List<RadioButton> TrayIconBehaviourRadioButtons = GridTrayIconBehaviour.Children.OfType<RadioButton>().ToList();
foreach (RadioButton rButton in TrayIconBehaviourRadioButtons)
{
if (rButton.Content.Equals(HonkySettings.Default.TrayIconBehaviour))
rButton.IsChecked = true;
}
List<RadioButton> FullscreenCaptureRadioButtons = GridFullscreenCapture.Children.OfType<RadioButton>().ToList();
foreach (RadioButton rButton in FullscreenCaptureRadioButtons)
{
if (rButton.Content.Equals(HonkySettings.Default.FullscreenCapture))
rButton.IsChecked = true;
}
if (RadioButtonQualityPNG.Content.Equals(HonkySettings.Default.ScreenCaptureQuality))
RadioButtonQualityPNG.IsChecked = true;
else RadioButtonQualityJPG.IsChecked = true;
}
I've got HonkyGuiControls, which contains WPF User Controls that I use in my HonkySettingsWindow, if needed, I'd be ready to create a custom RadioButton to bind my settings to them.
I already tried to create a User Control called CustomRadioButton and bind its IsCheckedProperty to something like this:
public Boolean IsChecked
{
get
{
if (CustomRadioButton.Content.Equals(HonkySettings.Default.TrayIconBehaviour)) return true;
else return false;
}
set
{
HonkySettings.Default.TrayIconBehaviour = CustomRadioButton.Content.ToString();
}
}
But the CustomRadioButton IsChecked Property wouldn't bind to it, because I'd need to create a DependencyProperty, and I have no idea how I should do the same thing with a DependencyProperty. Help please.
If you want to this using binding, try this
xaml
<Window x:Class="Stackoverflow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Stackoverflow"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:SettingsConverter x:Key="settingsConverter"/>
</Window.Resources>
<StackPanel>
<RadioButton GroupName="OnTrayClick" Content="Show settings window">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource myNameConverter}">
<Binding Path="HonkySettings.Default.TrayIconBehaviour"/>
<Binding Path="Content" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</RadioButton.IsChecked>
</RadioButton>
<RadioButton GroupName="OnTrayClick" Content="Open upload dialog">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource myNameConverter}">
<Binding Path="HonkySettings.Default.TrayIconBehaviour"/>
<Binding Path="Content" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</RadioButton.IsChecked>
</RadioButton>
<RadioButton GroupName="OnTrayClick" Content="Open file indexer">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource myNameConverter}">
<Binding Path="HonkySettings.Default.TrayIconBehaviour"/>
<Binding Path="Content" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</RadioButton.IsChecked>
</RadioButton>
<RadioButton GroupName="OnTrayClick" Content="Open image gallery">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource myNameConverter}">
<Binding Path="HonkySettings.Default.TrayIconBehaviour"/>
<Binding Path="Content" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</RadioButton.IsChecked>
</RadioButton>
<RadioButton GroupName="OnTrayClick" Content="Take a screenshot (3 seconds delay)">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource myNameConverter}">
<Binding Path="HonkySettings.Default.TrayIconBehaviour"/>
<Binding Path="Content" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</RadioButton.IsChecked>
</RadioButton>
</StackPanel>
Converter
public class SettingsConverter:IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values != null && values.Count() == 2)
return values.First() == values.Last();
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
if you making alot of this kind of binding as i can see there so to reduce xaml code we can do it this way as below
xaml
<Window x:Class="Stackoverflow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Stackoverflow"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<RadioButton GroupName="OnTrayClick" Content="Show settings window" IsChecked="{local:RadioButtonBinding HonkySettings.Default.TrayIconBehaviour}"/>
<RadioButton GroupName="OnTrayClick" Content="Open upload dialog" IsChecked="{local:RadioButtonBinding HonkySettings.Default.TrayIconBehaviour}"/>
<RadioButton GroupName="OnTrayClick" Content="Open file indexer" IsChecked="{local:RadioButtonBinding HonkySettings.Default.TrayIconBehaviour}"/>
<RadioButton GroupName="OnTrayClick" Content="Open image gallery" IsChecked="{local:RadioButtonBinding HonkySettings.Default.TrayIconBehaviour}"/>
<RadioButton GroupName="OnTrayClick" Content="Take a screenshot (3 seconds delay)" IsChecked="{local:RadioButtonBinding HonkySettings.Default.TrayIconBehaviour}"/>
</StackPanel>
RadioButtonBinding
public class RadioButtonBinding : MultiBinding
{
public RadioButtonBinding(string propName)
{
Bindings.Add(new Binding(propName));
Bindings.Add(new Binding("Content") { RelativeSource = new RelativeSource(RelativeSourceMode.Self) });
Converter = new SettingsConverter();
}
}
converter
public class SettingsConverter:IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values != null && values.Count() == 2)
return values.First() == values.Last();
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Related
TextBlock background color not changing.
I've bound my data to a TextBlock which updates with INotifyPropertyChanged, and the converter does fire.
public class Oddsindicator : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string myPrice = "0";
string tradePrice = "0";
var colorRed = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FFB0E0E6");
var colorWhite = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("White");
var unchanged = new SolidColorBrush(colorRed);
var changed = new SolidColorBrush(colorGreen);
if (values[0] != DependencyProperty.UnsetValue)
{
myPrice = values[0].ToString();
tradePrice = values[1].ToString();
}
if (myPrice == tradePrice)
{
return unchanged;
}
else
{
return changed;
}
}
}
XAML:
<Window.Resources>
<local:Oddsindicator x:Key="Oddsindicator" >
</local:Oddsindicator>
</Window.Resources>
<TextBlock Text="{Binding BackPrice, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextAlignment="Center" Margin="1" Grid.Row="4" Grid.Column="2" />
<TextBlock>
<TextBlock.Background>
<MultiBinding Converter="{StaticResource Oddsindicator}">
<Binding Path="BackPrice"/>
<Binding Path="Lasttradedprice" />
</MultiBinding>
</TextBlock.background>
</TextBlock>
I've used break points at the return and they both fire. My bound value updates perfectly. The converters comparing the values and giving the correct results, just not updating the TextBlock.
(This should in fact be a comment but I need the formatting features of an answer)
You have two TextBlocks. The second (for which you set the background) has no Text and is probably of 0 size.
Try putting the TextBlock.Background in the first TextBlock:
<TextBlock Text="{Binding BackPrice, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextAlignment="Center" Margin="1" Grid.Row="4" Grid.Column="2" >
<TextBlock.Background>
<MultiBinding Converter="{StaticResource Oddsindicator}">
<Binding Path="BackPrice"/>
<Binding Path="Lasttradedprice" />
</MultiBinding>
</TextBlock.Background>
</TextBlock>
I want the combo box to be enable when pressing one of the radio buttons.
<RadioButton x:Name="A" GroupName="rButton" Content="A" Grid.Column="4"/>
<RadioButton x:Name="B" GroupName="rButton" Content="B" Grid.Column="4"/>
<RadioButton x:Name="C" GroupName="rButton" Content="C" Grid.Column="4"/>
<RadioButton x:Name="D" GroupName="rButton" Content="D" Grid.Column="4"/>
<ComboBox IsEnabled="{Binding IsChecked,?? }" Grid.Column="5" Width="120" Height="30"/>
If you want to solve this via Bindings (and you should), you need a MultiBindingConverter that returns true as long as one of the values is true (boolean OR):
public class BooleanOrConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (object value in values)
{
if (value is bool && (bool) value)
return true;
}
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return Enumerable.Repeat(DependencyProperty.UnsetValue, targetTypes.Length).ToArray();
}
}
Definition:
<Window.Resources>
<local:BooleanOrConverter x:Key="OrConverter"/>
</Window.Resources>
Usage:
<RadioButton x:Name="RadioButtonSource" GroupName="rButton" Content="A" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonToken" GroupName="rButton" Content="B" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonII" GroupName="rButton" Content="C" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonUkey" GroupName="rButton" Content="D" Grid.Column="4"/>
<ComboBox Grid.Column="5" Width="120" Height="30">
<ComboBox.IsEnabled>
<MultiBinding Converter="{StaticResource OrConverter}">
<Binding ElementName="RadioButtonSource" Path="IsChecked"/>
<Binding ElementName="RadioButtonToken" Path="IsChecked"/>
<Binding ElementName="RadioButtonII" Path="IsChecked"/>
<Binding ElementName="RadioButtonUkey" Path="IsChecked"/>
</MultiBinding>
</ComboBox.IsEnabled>
</ComboBox>
This way, as soon as any of the RadioButtons's IsChecked properties becomes true, the ComboBox is enabled. If you reset the RadioButtons, it get's disabled again.
I want to bind the SelectedDate in RadCalendar, to two CurrentDate in different RadScheduleView. How can i do that?
<telerik:RadCalendar Name="radCalendar"
Canvas.Left="80" Canvas.Top="200"
Height="320" Width="400"
SelectedDate="{Binding CurrentDate, ElementName=radScheduleView, Mode=TwoWay}"
SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}">
</telerik:RadCalendar>
I want to have two ElementName=radScheduleView and ElementName=radScheduleView1
EDIT
here's my code that need to be bound
<telerik:RadCalendar Name="radCalendar"
Canvas.Left="80" Canvas.Top="200"
Height="320" Width="400"
SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}" >
<telerik:RadCalendar.SelectedDate>
<MultiBinding Converter="MultiValueConverter" Mode="TwoWay">
<Binding ElementName="radScheduleView" Path="CurrentDate"/>
<Binding ElementName="radScheduleView1" Path="CurrentDate"/>
</MultiBinding>
</telerik:RadCalendar.SelectedDate>
<telerik:RadScheduleView Name="radScheduleView1"
Canvas.Left="60" Canvas.Top="130"
Height="420" Width="570"
AppointmentsSource="{Binding Appointments}"
SelectedAppointment="{Binding SelectedAppointment, Mode=TwoWay}"
ActiveViewDefinitionIndex="{Binding ActiveViewDefinitionIndex,Mode=TwoWay}"
CurrentDate="{Binding CurrentDate, Mode=TwoWay}">
<telerik:RadScheduleView.ViewDefinitions>
<telerik:DayViewDefinition MinorTickLength="10min" />
</telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>
<telerik:RadScheduleView Name="radScheduleView"
Canvas.Left="60" Canvas.Top="130"
Height="420" Width="570"
AppointmentsSource="{Binding Appointments}"
SelectedAppointment="{Binding SelectedAppointment, Mode=TwoWay}"
ActiveViewDefinitionIndex="{Binding ActiveViewDefinitionIndex,Mode=TwoWay}"
CurrentDate="{Binding CurrentDate, Mode=TwoWay}">
<telerik:RadScheduleView.ViewDefinitions>
<telerik:DayViewDefinition MinorTickLength="1h" />
</telerik:RadScheduleView.ViewDefinitions>
You can use MultiBinding instead of simple Binding and use it with the IMultiValueConverter implementation like the following one:
public class MultiValueConverterExtension : MarkupExtension, IMultiValueConverter {
public override object ProvideValue(IServiceProvider serviceProvider) {
return this;
}
object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
return values[1];
}
object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) {
return new object[] { value, value };
}
}
In this case XAML will be like this one:
<telerik:RadCalendar Name="radCalendar"
Canvas.Left="80" Canvas.Top="200"
Height="320" Width="400"
SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}">
<telerik:RadCalendar.SelectedDate>
<MultiBinding Converter="{local:MultiValueConverter}" Mode="TwoWay">
<Binding ElementName="radScheduleView" Path="CurrentDate"/>
<Binding ElementName="radScheduleView1" Path="CurrentDate"/>
</MultiBinding>
</telerik:RadCalendar.SelectedDate>
</telerik:RadCalendar>
I have 10 textboxes and I want there addition to be shown in a single textblock on lost_focus UpdateSourceTrigger property.
If you need to update the sum on TextBox lost focus event you can use classic events. This is the XAML (I used just four TextBoxes, but it is easy to extend):
<StackPanel>
<TextBox Name="txt01" Margin="3" HorizontalAlignment="Stretch" LostFocus="txt_LostFocus" TextChanged="txt_TextChanged" />
<TextBox Name="txt02" Margin="3" HorizontalAlignment="Stretch" LostFocus="txt_LostFocus" TextChanged="txt_TextChanged" />
<TextBox Name="txt03" Margin="3" HorizontalAlignment="Stretch" LostFocus="txt_LostFocus" TextChanged="txt_TextChanged" />
<TextBox Name="txt04" Margin="3" HorizontalAlignment="Stretch" LostFocus="txt_LostFocus" TextChanged="txt_TextChanged" />
<TextBlock Name="sum" Margin="3,10,3,3" />
</StackPanel>
In the code you have the event handlers:
private void txt_LostFocus(object sender, RoutedEventArgs e)
{
int value1;
int value2;
TextBox textBox = (TextBox)sender;
if (textBox.Tag is bool && (bool)textBox.Tag)
{
if (Int32.TryParse(textBox.Text, out value1))
{
if (String.IsNullOrEmpty(sum.Text))
{
sum.Text = textBox.Text;
}
else
{
Int32.TryParse(sum.Text, out value2);
sum.Text = Convert.ToString(value1 + value2);
}
}
textBox.Tag = false;
}
}
private void txt_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textBox = (TextBox)sender;
textBox.Tag = true;
}
On the other side, if you can give up the "LostFocus" requirement, you can use MultiBinding (in this case it works just in "PropertyChanged mode", since TextBoxes are now the sources):
<StackPanel>
<TextBox Name="txt01" Margin="3" HorizontalAlignment="Stretch" />
<TextBox Name="txt02" Margin="3" HorizontalAlignment="Stretch" />
<TextBox Name="txt03" Margin="3" HorizontalAlignment="Stretch" />
<TextBox Name="txt04" Margin="3" HorizontalAlignment="Stretch" />
<TextBlock Name="sum" Margin="3,10,3,3">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource AddValueConverter}" Mode="OneWay">
<MultiBinding.Bindings>
<Binding ElementName="txt01" Path="Text" />
<Binding ElementName="txt02" Path="Text" />
<Binding ElementName="txt03" Path="Text" />
<Binding ElementName="txt04" Path="Text" />
</MultiBinding.Bindings>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
You just need to write a simple converter:
public class AddValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
int sum = 0;
int result;
foreach(object value in values)
{
if (Int32.TryParse(System.Convert.ToString(value), out result))
{
sum += result;
}
}
return System.Convert.ToString(sum);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
I have a listbox which stores records of XML file. My XMLfile has multiple elements like Name, Destination, employee ID. The listbox would display all the name contents of the XMLfile.
<Information>
<Name>Goutham</Name>
<Destination>dar</Destination>
<EmployeeID>da</EmployeeID>
</Information>
<Information>
<Name>Adam</Name>
<Destination>ads</Destination>
<EmployeeID>dwa</EmployeeID>
</Information>
<Information>
<Name>dwad</Name>
<Destination>wadwa</Destination>
<EmployeeID>daw</EmployeeID>
</Information>
The listbox displays all the different names like Goutham,Adam,dwad.
Now if I select Goutham in the listbox, I need to display all the details of Goutham on the textbox. How do i do it?
This is my xaml file
<ListBox Height="251" HorizontalAlignment="Left" Margin="330,23,0,0" Name="listBox1" VerticalAlignment="Top" Width="170" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name" ItemsSource="{Binding}"/>
<TextBox Height="23" HorizontalAlignment="Left" Margin="141,42,0,0" Name="textBox1" VerticalAlignment="Top" Width="173" Text="{Binding ElementName= listbox1, Path=SelectedItem.Name}"/>
If the listbox fills up it should allready work, you just have a typo in the ElementName binding it should be listBox1.
Also if you want all the details not just the Name you could make a converter and leave only SelectedItem in the binding path. The converter would then format the details form the Information instance returning a string to be displayed in the texbox, or just use several textboxes.
Another option is to have MultiBinding with StringFormat:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{0} {1} {2}">
<Binding ElementName="listbox1", Path="SelectedItem.Name" />
<Binding ElementName="listbox1", Path="SelectedItem.Destination" />
<Binding ElementName="listbox1", Path="SelectedItem.EmployeeID" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
You can bind ListBox to once specific property say Name & then bind TextBlock to this listbox. Depending upon your need, you can have individual TextBlocks for each property or a single TextBlock... as shown below...
<Window x:Class="ListBoxDataBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:ListBoxDataBinding"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<c:EmployeeConverter x:Key="myEmployeeConverter"/>
</Window.Resources>
<StackPanel Orientation="Vertical">
<ListBox x:Name="lbEmployee">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Width="248" Height="24" Text="Employee Name" />
<TextBlock Grid.Row="0" Grid.Column="1" Width="248" Height="24" Text="{Binding ElementName=lbEmployee, Path=SelectedItem.Name}" />
<TextBlock Grid.Row="1" Grid.Column="0" Width="248" Height="24" Text="Employee EmployeeId" />
<TextBlock Grid.Row="1" Grid.Column="1" Width="248" Height="24" Text="{Binding ElementName=lbEmployee, Path=SelectedItem.EmployeeId}" />
<TextBlock Grid.Row="2" Grid.Column="0" Width="248" Height="24" Text="Employee Destination" />
<TextBlock Grid.Row="2" Grid.Column="2" Width="248" Height="24" Text="{Binding ElementName=lbEmployee, Path=SelectedItem.Destination}" />
<TextBlock Grid.Row="3" Grid.Column="0" Width="248" Height="24" Text="Employee Details" />
<TextBlock Grid.Row="3" Grid.Column="2" Width="248" Height="24">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myEmployeeConverter}" ConverterParameter="FormatEmployee">
<Binding ElementName="lbEmployee" Path="SelectedItem.Name" />
<Binding ElementName="lbEmployee" Path="SelectedItem.EmployeeId" />
<Binding ElementName="lbEmployee" Path="SelectedItem.Destination" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</StackPanel>
Code behind....
public partial class MainWindow : Window
{
private List<Employee> _lstEmployees;
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
_lstEmployees = new List<Employee>();
_lstEmployees.Add(new Employee { Name = "Goutham", EmployeeId = "da", Destination = "dar" });
_lstEmployees.Add(new Employee { Name = "Adam", EmployeeId = "dwa", Destination = "ads" });
_lstEmployees.Add(new Employee { Name = "dwad", EmployeeId = "daw", Destination = "wadwa" });
lbEmployee.ItemsSource = _lstEmployees;
}
}
public class EmployeeConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string name;
switch ((string)parameter)
{
case "FormatEmployee":
if (values[0] is String)
{
name = values[0] + ", " + values[1] + ", " + values[2];
}
else
{
name = String.Empty;
}
break;
default:
name = String.Empty;
break;
}
return name;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
string[] splitValues = ((string)value).Split(' ');
return splitValues;
}
}