How to make a list of buttons dynamically and show them in the ItemsControl
up vote
0
down vote
favorite
I have a list of products that I need to load in buttons, but I can not get the buttons to appear.
code xaml:
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
picture of how the list is displayed (buttons should appear):
enter image description here
wpf
add a comment |
up vote
0
down vote
favorite
I have a list of products that I need to load in buttons, but I can not get the buttons to appear.
code xaml:
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
picture of how the list is displayed (buttons should appear):
enter image description here
wpf
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
How and where is theProductos
property that you are binding to defined?
– mm8
Nov 8 at 13:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a list of products that I need to load in buttons, but I can not get the buttons to appear.
code xaml:
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
picture of how the list is displayed (buttons should appear):
enter image description here
wpf
I have a list of products that I need to load in buttons, but I can not get the buttons to appear.
code xaml:
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
picture of how the list is displayed (buttons should appear):
enter image description here
wpf
wpf
asked Nov 7 at 20:30
Marcela Gonzalez
1
1
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
How and where is theProductos
property that you are binding to defined?
– mm8
Nov 8 at 13:31
add a comment |
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
How and where is theProductos
property that you are binding to defined?
– mm8
Nov 8 at 13:31
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
How and where is the
Productos
property that you are binding to defined?– mm8
Nov 8 at 13:31
How and where is the
Productos
property that you are binding to defined?– mm8
Nov 8 at 13:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Check the following:
• Make sure your property named "Productos" is public.
• Make sure you're using an collection type of "ObservableCollection"
• If you're using the MVVM pattern and your property is in a model class, make sure your model is set to the context of the view.
MyViewModel model = new MyViewModel();
this.DataContext = model;
• Make sure the ItemsControl is actually visible. Set height and width to fix value for testing purposes.
• If your not using MVVM and your property named "Productos" is in the partial class of the view, make sure to set the binding on the partial class. To do this give your control/view a name and set the binding directly on the view control element.
<UserControl x:Name="Control_View" />
<ItemsControl ItemsSource="{Binding Path=OpenUserProfileEditor, ElementName=Control_View}" />
Alos, try making your ItemsControl like mine below. (Example)
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Check the following:
• Make sure your property named "Productos" is public.
• Make sure you're using an collection type of "ObservableCollection"
• If you're using the MVVM pattern and your property is in a model class, make sure your model is set to the context of the view.
MyViewModel model = new MyViewModel();
this.DataContext = model;
• Make sure the ItemsControl is actually visible. Set height and width to fix value for testing purposes.
• If your not using MVVM and your property named "Productos" is in the partial class of the view, make sure to set the binding on the partial class. To do this give your control/view a name and set the binding directly on the view control element.
<UserControl x:Name="Control_View" />
<ItemsControl ItemsSource="{Binding Path=OpenUserProfileEditor, ElementName=Control_View}" />
Alos, try making your ItemsControl like mine below. (Example)
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
add a comment |
up vote
1
down vote
Check the following:
• Make sure your property named "Productos" is public.
• Make sure you're using an collection type of "ObservableCollection"
• If you're using the MVVM pattern and your property is in a model class, make sure your model is set to the context of the view.
MyViewModel model = new MyViewModel();
this.DataContext = model;
• Make sure the ItemsControl is actually visible. Set height and width to fix value for testing purposes.
• If your not using MVVM and your property named "Productos" is in the partial class of the view, make sure to set the binding on the partial class. To do this give your control/view a name and set the binding directly on the view control element.
<UserControl x:Name="Control_View" />
<ItemsControl ItemsSource="{Binding Path=OpenUserProfileEditor, ElementName=Control_View}" />
Alos, try making your ItemsControl like mine below. (Example)
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
add a comment |
up vote
1
down vote
up vote
1
down vote
Check the following:
• Make sure your property named "Productos" is public.
• Make sure you're using an collection type of "ObservableCollection"
• If you're using the MVVM pattern and your property is in a model class, make sure your model is set to the context of the view.
MyViewModel model = new MyViewModel();
this.DataContext = model;
• Make sure the ItemsControl is actually visible. Set height and width to fix value for testing purposes.
• If your not using MVVM and your property named "Productos" is in the partial class of the view, make sure to set the binding on the partial class. To do this give your control/view a name and set the binding directly on the view control element.
<UserControl x:Name="Control_View" />
<ItemsControl ItemsSource="{Binding Path=OpenUserProfileEditor, ElementName=Control_View}" />
Alos, try making your ItemsControl like mine below. (Example)
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Check the following:
• Make sure your property named "Productos" is public.
• Make sure you're using an collection type of "ObservableCollection"
• If you're using the MVVM pattern and your property is in a model class, make sure your model is set to the context of the view.
MyViewModel model = new MyViewModel();
this.DataContext = model;
• Make sure the ItemsControl is actually visible. Set height and width to fix value for testing purposes.
• If your not using MVVM and your property named "Productos" is in the partial class of the view, make sure to set the binding on the partial class. To do this give your control/view a name and set the binding directly on the view control element.
<UserControl x:Name="Control_View" />
<ItemsControl ItemsSource="{Binding Path=OpenUserProfileEditor, ElementName=Control_View}" />
Alos, try making your ItemsControl like mine below. (Example)
<ItemsControl ItemsSource="{Binding Path=Productos}" Grid.Row="4" Grid.Column="1" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SeleccionarOpcionesCotizacionesView2}">
<Button Command="{Binding CmdCuenta}" Style="{StaticResource TransparentStyle}" Width="775" Height="157"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
edited Nov 8 at 12:24
answered Nov 8 at 6:32
B.Spangenberg
1079
1079
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
add a comment |
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
Unless the command really is a property of the data item, it should be bound using a relative source to the main viewmodel (ItemsControl.DataContext).
– Peregrine
Nov 8 at 12:32
add a comment |
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197343%2fhow-to-make-a-list-of-buttons-dynamically-and-show-them-in-the-itemscontrol%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/26488934/add-items-to-itemscontrol
– Hanjun Chen
Nov 7 at 20:49
Make sure that Productos is a public property in the DataContext of your view. Instead of adding the DataTemplate to the ItemsControl's Resources, you may directly assign it to the ItemTemplate property, and omit the DataType.
– Clemens
Nov 7 at 21:08
How and where is the
Productos
property that you are binding to defined?– mm8
Nov 8 at 13:31