I am developing custom control.
Following Codes are written in generic.xaml
<Style TargetType="local:TwoListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TwoListBox">
<StackPanel Orientation="Horizontal">
<ListBox x:name="ListBoxForBasic" ItemsSource="{Binding}" DisplayMemberPath="NumValue" Margin="10"/>
<ListBox x:name="ListBoxForSorting" ItemsSource="{Binding}" DisplayMemberPath="NumValue" Margin="10"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
It is very simple, I have two ListBox and am trying to bind following data to two ListBox
public class SampleData
{
public int Num { get; set; }
public int NumValue { get; set; }
}
public class SampleDataList : List<SampleData>
{
public SampleDataList()
{
Add(new SampleData{ Num=1, NumValue=10});
Add(new SampleData { Num = 2, NumValue = 50 });
Add(new SampleData { Num = 3, NumValue = 20 });
Add(new SampleData { Num = 4, NumValue = 40 });
Add(new SampleData { Num = 5, NumValue = 30 });
}
}
In MainPage.xaml, I used sample data for TwoListBox custom control like this :
<local:TwoListBox DataContext="{StaticResource sampleData}"/>
If hit F5, TwoListBox custom control looks like this :
10 10
50 50
20 20
40 40
30 30
However, I would like to binding sorted data for second ListBox(ListBoxForSorting) like this :
10 10
50 20
20 30
40 40
30 50
In this case, What should I do for this?
Thanks in advance