multi Datacontext wpf
up vote
-1
down vote
favorite
Who can explain to me how to use two different datacontext ?
this is my file.xaml.cs :
public partial class MainWindow : Window
{
public MainWindow()
InitializeComponent();
DataContext = new string "Female", "Male", "Animal", "Safe", "Soft", "Hard", "Space", "Landscape", "Outside", "Inside",
"City", "France", "Flower", "Sunset", "Sky", "Fireworks", "Spring", "Winter", "Summer", "Fall", "Christmas", "Halloween",
"Ghost", "Demon", "Angel", "Watermelon", "Storm", "Waterfall", "Night", "Sun","Moon", "Dog", "Cat", "Food", "Cheese",
"Kancolle", "IT", "UFO", "Travel", "Sport", "Nightmare";
and here my file.xaml :
<ScrollViewer HorizontalAlignment="Left" Height="170" VerticalAlignment="Top" Width="97" Margin="10,149,0,0">
<ListBox ItemsSource="Binding .">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="Binding Path=." />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
Everything work well here, but i would like add an second ScrollViewer exactly like the first one, but with another content. so the datacontexte need to be different for each of them.
thank you for giving me a little of your time.
wpf xaml binding datacontext
New contributor
add a comment |
up vote
-1
down vote
favorite
Who can explain to me how to use two different datacontext ?
this is my file.xaml.cs :
public partial class MainWindow : Window
{
public MainWindow()
InitializeComponent();
DataContext = new string "Female", "Male", "Animal", "Safe", "Soft", "Hard", "Space", "Landscape", "Outside", "Inside",
"City", "France", "Flower", "Sunset", "Sky", "Fireworks", "Spring", "Winter", "Summer", "Fall", "Christmas", "Halloween",
"Ghost", "Demon", "Angel", "Watermelon", "Storm", "Waterfall", "Night", "Sun","Moon", "Dog", "Cat", "Food", "Cheese",
"Kancolle", "IT", "UFO", "Travel", "Sport", "Nightmare";
and here my file.xaml :
<ScrollViewer HorizontalAlignment="Left" Height="170" VerticalAlignment="Top" Width="97" Margin="10,149,0,0">
<ListBox ItemsSource="Binding .">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="Binding Path=." />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
Everything work well here, but i would like add an second ScrollViewer exactly like the first one, but with another content. so the datacontexte need to be different for each of them.
thank you for giving me a little of your time.
wpf xaml binding datacontext
New contributor
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Who can explain to me how to use two different datacontext ?
this is my file.xaml.cs :
public partial class MainWindow : Window
{
public MainWindow()
InitializeComponent();
DataContext = new string "Female", "Male", "Animal", "Safe", "Soft", "Hard", "Space", "Landscape", "Outside", "Inside",
"City", "France", "Flower", "Sunset", "Sky", "Fireworks", "Spring", "Winter", "Summer", "Fall", "Christmas", "Halloween",
"Ghost", "Demon", "Angel", "Watermelon", "Storm", "Waterfall", "Night", "Sun","Moon", "Dog", "Cat", "Food", "Cheese",
"Kancolle", "IT", "UFO", "Travel", "Sport", "Nightmare";
and here my file.xaml :
<ScrollViewer HorizontalAlignment="Left" Height="170" VerticalAlignment="Top" Width="97" Margin="10,149,0,0">
<ListBox ItemsSource="Binding .">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="Binding Path=." />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
Everything work well here, but i would like add an second ScrollViewer exactly like the first one, but with another content. so the datacontexte need to be different for each of them.
thank you for giving me a little of your time.
wpf xaml binding datacontext
New contributor
Who can explain to me how to use two different datacontext ?
this is my file.xaml.cs :
public partial class MainWindow : Window
{
public MainWindow()
InitializeComponent();
DataContext = new string "Female", "Male", "Animal", "Safe", "Soft", "Hard", "Space", "Landscape", "Outside", "Inside",
"City", "France", "Flower", "Sunset", "Sky", "Fireworks", "Spring", "Winter", "Summer", "Fall", "Christmas", "Halloween",
"Ghost", "Demon", "Angel", "Watermelon", "Storm", "Waterfall", "Night", "Sun","Moon", "Dog", "Cat", "Food", "Cheese",
"Kancolle", "IT", "UFO", "Travel", "Sport", "Nightmare";
and here my file.xaml :
<ScrollViewer HorizontalAlignment="Left" Height="170" VerticalAlignment="Top" Width="97" Margin="10,149,0,0">
<ListBox ItemsSource="Binding .">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="Binding Path=." />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
Everything work well here, but i would like add an second ScrollViewer exactly like the first one, but with another content. so the datacontexte need to be different for each of them.
thank you for giving me a little of your time.
wpf xaml binding datacontext
wpf xaml binding datacontext
New contributor
New contributor
New contributor
asked Nov 10 at 10:23
astrocurieux
84
84
New contributor
New contributor
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56
add a comment |
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You don't need to set different DataContexts.
Create two collection properties in your MainWindow class and set the DataContext to the window instance.
public IEnumerable<string> Collection1 get;
public IEnumerable<string> Collection2 get;
public MainWindow()
InitializeComponent();
Collection1 = new string ... ;
Collection2 = new string ... ;
DataContext = this;
Bind the ListBox's ItemSource to the collection properties:
<ListBox ItemsSource="Binding Collection1" ...>
...
<ListBox ItemsSource="Binding Collection2" ...>
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You don't need to set different DataContexts.
Create two collection properties in your MainWindow class and set the DataContext to the window instance.
public IEnumerable<string> Collection1 get;
public IEnumerable<string> Collection2 get;
public MainWindow()
InitializeComponent();
Collection1 = new string ... ;
Collection2 = new string ... ;
DataContext = this;
Bind the ListBox's ItemSource to the collection properties:
<ListBox ItemsSource="Binding Collection1" ...>
...
<ListBox ItemsSource="Binding Collection2" ...>
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
add a comment |
up vote
0
down vote
accepted
You don't need to set different DataContexts.
Create two collection properties in your MainWindow class and set the DataContext to the window instance.
public IEnumerable<string> Collection1 get;
public IEnumerable<string> Collection2 get;
public MainWindow()
InitializeComponent();
Collection1 = new string ... ;
Collection2 = new string ... ;
DataContext = this;
Bind the ListBox's ItemSource to the collection properties:
<ListBox ItemsSource="Binding Collection1" ...>
...
<ListBox ItemsSource="Binding Collection2" ...>
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You don't need to set different DataContexts.
Create two collection properties in your MainWindow class and set the DataContext to the window instance.
public IEnumerable<string> Collection1 get;
public IEnumerable<string> Collection2 get;
public MainWindow()
InitializeComponent();
Collection1 = new string ... ;
Collection2 = new string ... ;
DataContext = this;
Bind the ListBox's ItemSource to the collection properties:
<ListBox ItemsSource="Binding Collection1" ...>
...
<ListBox ItemsSource="Binding Collection2" ...>
You don't need to set different DataContexts.
Create two collection properties in your MainWindow class and set the DataContext to the window instance.
public IEnumerable<string> Collection1 get;
public IEnumerable<string> Collection2 get;
public MainWindow()
InitializeComponent();
Collection1 = new string ... ;
Collection2 = new string ... ;
DataContext = this;
Bind the ListBox's ItemSource to the collection properties:
<ListBox ItemsSource="Binding Collection1" ...>
...
<ListBox ItemsSource="Binding Collection2" ...>
answered Nov 10 at 10:53
Clemens
86.4k884166
86.4k884166
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
add a comment |
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
thank you for your help, it's a simple solution and very comprehenssible.
– astrocurieux
Nov 10 at 11:19
add a comment |
astrocurieux is a new contributor. Be nice, and check out our Code of Conduct.
astrocurieux is a new contributor. Be nice, and check out our Code of Conduct.
astrocurieux is a new contributor. Be nice, and check out our Code of Conduct.
astrocurieux is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237998%2fmulti-datacontext-wpf%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
As a note, it looks odd that the ListBox is inside a ScrollViewer. A ListBox already provides scrolling by a ScrollViewer in its ControlTemplate.
– Clemens
Nov 10 at 10:56