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










share|improve this question






















  • 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















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










share|improve this question






















  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 the Productos 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










  • 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
















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












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>





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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>





share|improve this answer























  • 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















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>





share|improve this answer























  • 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













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>





share|improve this answer














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>






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()