Add multiple buttons [closed] - wpf

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So I want to add x buttons this value is going to be from a variable that is inputed by the user
I put like 5 tables and 5 buttons will appear.
Any help?

Sounds like you want an ItemsControl. It let's you define a template (in your case, a button) and bind to a collection of items like this:
<ItemsControl ItemsSource={Binding MyCollectionOfObjects>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding MyStringProperty}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

Related

Call RelayCommand in WPF-Control from WPF-Windows (XAML) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a WPF UserControl with a ViewModel as DataContext. This ViewModel also contains RelayCommands. From the control I can call these commands (e.g. with a button) <Button Command="{Binding SaveCommand}">Save</Button>. Now I want to place the control in a window and call the commands from there <Button Command="{Binding SaveCommand}" CommandTarget="{Binding ElementName=myControl}">Save</Button>. But this does not work. How can I call a command in a child control in XAML?
Thanks a lot
Markus
If your main window has different DataContext and you can't reach this command through it you can write
<Button Command="{Binding DataContext.SaveCommand, ElementName=myControl}">Save</Button>

How to even out a few text-boxes in stack-panel in XAML? [duplicate]

This question already has an answer here:
Fill all available space in ItemsComtrol with same width size of elements
(1 answer)
Closed 3 years ago.
I have 7 text-boxes containing weekday's names from Monday to Sunday. My problem is that I want to put each of those in a textbox inside the stack panel and get them to fill the entire stack panel horizontally so that each textbox has the same width.
How can that be achieved instead of the picture below of my attempt?
Use a WrapPanel instead and specify a minimum ItemWidth
<WrapPanel ItemWidth="140">
<TextBlock Text="Monday"/>
<TextBlock Text="Tuesday"/>
<TextBlock Text="Wednesday"/>
<TextBlock Text="Thursday"/>
<TextBlock Text="Friday"/>
<TextBlock Text="Saturday"/>
<TextBlock Text="Sunday"/>
</WrapPanel>

WPF listBox collection slection changes are not working propely [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to load a collection to listbox as follows.(one item in listbox contains a image and a text block) IF i click each item by item in outside of the image( area 2) selection change working fine(highlight correctly); but if do the selection change by clicking each image this want work correctly.What is the reason behind this?
item by item
<DataTemplate x:Key="ObjectGalleryDataTemplate" DataType="{x:Type loc:ObjectTypes}" >
<Button Margin="3" Width="80" Height="80" Click="click_object"BorderBrush="Transparent" Tag="{Binding ObjectTypeID}">
<ItemsPanelTemplate x:Key="ObjectGalleryItemsPanelTemplate">
<UniformGrid Rows="1" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<Grid><ListBox x:Name="ObjectTypesGallery" SelectionMode="Single" SelectionChanged="objectType_clik" BorderBrush="Transparent" SelectedIndex="0" ItemsSource="{Binding}" ItemTemplate="{DynamicResource ObjectGalleryDataTemplate}" ItemsPanel="{DynamicResource ObjectGalleryItemsPanelTemplate}">
</ListBox>
</Grid>
</StackPanel>
Since you asked:
what is the reason behind this?
The reason is that each item in a list box is automatically made selectable (so that you can choose one or more list items as part of your UI). But since you have included a button in your list item template, when you click on the button, the system is responding to the button being clicked first, in front of the list item.
You didn't specify how you want this to behave. I would guess that you should either use an <ItemsControl> if you don't want to be able to select individual items, or change your <Button> to an <Image> or something similar if you don't want to be able to click the icon in the center. Or, if you want both click events to fire (the button click, and the list item selection click), you will need to implement this manually using event handlers.

Find control in templated WPF datagrid [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
get value of checkbox from datagrid? C#
I am trying to find a control inside the selected row in a templated DataGrid.
<DataGridTemplateColumn Header="Local">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkImport" IsChecked="{Binding IsLocalized}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
I am trying the following code:
var selectedRow = (DataGridRow) gridFileScan.ItemContainerGenerator.ContainerFromItem(gridFileScan.SelectedItem);
CheckBox chkImport = FindVisualChild<CheckBox>(selectedRow);
but chkImport is always null. Any ideas ??
When you debug you should be able to see the method recurse the VisualTree.
You can see the Visual Tree by using the Visual Tree Visualizer
The implementation of FindVisualChild might be flawed or the VisualTree doesn't look like what you expect.
Found it. I just had to call this method after modifying ItemsSource:
gridFileScan.UpdateLayout();

Use Ribbon Control in WPF Toolkit in XAML [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
How to use the Ribbon control in WPf toolkit in my XAML?
How to include the namespaces for ribbon in XAML?
Good link Trainee4Life, just like this one.
As per the walkthrough:
<r:RibbonTab Label="Banking">
<r:RibbonGroup>
<r:RibbonButton Command="me:AppCommands.Cut"/>
<r:RibbonButton Command="me:AppCommands.Copy"/>
<r:RibbonButton Command="me:AppCommands.Paste"/>
</r:RibbonGroup>
<r:RibbonGroup>
<r:RibbonButton Command="me:AppCommands.AddNew"/>
<r:RibbonButton Command="me:AppCommands.Clear" />
<r:RibbonButton Command="me:AppCommands.Delete"/>
</r:RibbonGroup>
<r:RibbonGroup>
<r:RibbonButton Command="me:AppCommands.DownloadStatements"/>
<r:RibbonButton Command="me:AppCommands.DownloadCreditCards"/>
<r:RibbonButton Command="me:AppCommands.Transfer"/>
</r:RibbonGroup>
</r:RibbonTab>
I did work with Ribbon for a considerable amount of time. Nothing beats these tutorials.
http://www.uxpassion.com/2009/08/wpf-ribbon-control-roadmap-and-look-into-the-future/
And for the namespace problem, include a reference to RibbonControlsLibrary.dll in your project, and use the following line to point to the namespace.
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"

Resources