wpf layout-system problem - wpf

I'm not too familiar with wpf layout-system. so i'm ready to start and understanding that. at the first of road i have a problem with wpf. so according to below markup, i have 4 button which when we run project everything is true.
<Window ... WindowStartupLocation="CenterOwner" SizeToContent="WidthAndHeight" Name="wMessage" ShowInTaskbar="False" ResizeMode="NoResize" WindowStyle="SingleBorderWindow">
<WrapPanel Orientation="Horizontal">
<Button Content="Button 1" Margin="10" />
<Button Content="Button 2" Margin="10" />
<Button Content="Button 3" Margin="10" />
<Button Content="Button 4" Margin="10" />
</WrapPanel>
at the right side and bottom of window something appears like a border which i don't know this comes from where!!!
alt text http://www.4freeimagehost.com/uploads/098a981c7a36.png

The problem i that you have given a Margin="10" for every button. By default it takes that single value for all the Four sides. If you don't want the Blank Space for Top and bottom but want them between the buttons then cahnge the XAML to following.
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
By default if you give only 2 values, first one is taken for both Left and Right and second one is taken for both Top and Bottom.

Related

WPF Tabs Stack button

I have 5 buttons stacked as below, with each button corresponding to a grid containing datagrid. Now I click on the 2nd button below, I want the second button to move up grid.row="1" with its grid part to move up Grid.Row="2" and its Grid.SpanRow = "5" (the first button remains in place but its grid will disapear) and it must have an up animation. but I can't know how to do this and how to hide grids when another grid is showing. Anyone have any other ideas for me? Sorry for my bad discription cuz i just started coding with wpf 2 weaks ago. Thanks all guys first.
This is my code:
<Border>
<Grid>
<Grid.RowDefinitions>
...*11Rows (I dont know why this isn't shown, Grid.RowDefinitions)
</Grid.RowDefinitions>
<Button > Phương tiện</Button>
<Button Grid.Row="7" Name="btn1"> Điểm đánh dấu
</Button>
<Button Grid.Row="8">Cây tốc độ</Button>
<Button Grid.Row="9">Tìm kiếm nhanh</Button>
<Button Grid.Row="10">Mô phỏng lịch sử</Button>
<Button Grid.Row="11">Điểm đánh dấu</Button>
<Grid Grid.Row="1" Grid.RowSpan="6" x:Name="gr1"> blabla </Grid>
</Grid>
</Border>
[2

How to fix "materialDesign" is not defined in wpf/xaml

I recently added material design to my wpf project. Everything worked fine so far, untill I tried to add a dialog.
https://gyazo.com/13e65442cdd241108fa397bd1c5695e6
I googled the whole internet off but could not find a solution
<StackPanel
VerticalAlignment="Center">
<!--the request to open the dialog will bubble up to the top-most DialogHost, but we can used the attached property based event to handle the response -->
<Button
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
materialDesign:DialogHost.DialogClosingAttached="Sample2_DialogHost_OnDialogClosing"
Width="128">
<Button.CommandParameter>
<StackPanel
Margin="16">
<ProgressBar
Style="{DynamicResource MaterialDesignCircularProgressBar}"
HorizontalAlignment="Center"
Margin="16"
IsIndeterminate="True"
Value="0" />
<Button
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
CommandParameter="Sample2Cancel"
HorizontalAlignment="Center">
CANCEL
</Button>
</StackPanel>
</Button.CommandParameter>
PASS VIEW
</Button>
<Button
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
Width="128"
Margin="0 32 0 0">
<Button.CommandParameter>
<!-- the simplest view model of all, a DateTime. the view can be found in the resources of MainWindow.xaml -->
<system:DateTime xmlns:system="clr-namespace:System;assembly=mscorlib">
1966-JUL-30
</system:DateTime>
</Button.CommandParameter>
PASS MODEL
</Button>
</StackPanel>
Getting the following error:
https://gyazo.com/c3038b28c90ebd81c94bea5a7bc9b671
I expected to have a dialog like in the demo of material design toolkit.
https://gyazo.com/435b4136a05678455386848548c9c6de
I had to add: xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
at the top of the xaml file

Should I use a ContextMenu to show a couple of buttons?

I am developing a WPF application and I want the following functionality: If a user right clicks on a progress bar a small context menu should popup at the clicked position. This menu should just contain a couple of buttons which are lined up horizontally. Should I use the ContextMenu for this or are there better suitable WPF elements?
I tried a ContextMenu and this is how it looks like:
This is the XAML:
<ProgressBar x:Name="PgF" Height="10" Value="{Binding Path=FileCurrentMs}" Maximum="{Binding Path=FileLengthMs}">
<ProgressBar.ContextMenu>
<ContextMenu>
<StackPanel Orientation="Horizontal">
<Button Content="A"/>
<Button Content="B"/>
<Button Content="C"/>
</StackPanel>
</ContextMenu>
</ProgressBar.ContextMenu>
</ProgressBar>
In the ContextMenu I have the space to the left and to the right which I don’t want and I read in other posts that it is not simple just to remove this space. Any ideas?
Try like this :
<ProgressBar x:Name="PgF" Height="10" Value="{Binding Path=FileCurrentMs}" Maximum="{Binding Path=FileLengthMs}">
<ProgressBar.ContextMenu>
<ContextMenu>
<MenuItem>
<MenuItem.Template>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="A" Margin="2"/>
<Button Content="B" Margin="2"/>
<Button Content="C" Margin="2"/>
</StackPanel>
</ControlTemplate>
</MenuItem.Template>
</MenuItem>
</ContextMenu>
</ProgressBar.ContextMenu>
</ProgressBar>
You need to put all buttons in a single menu item :) good luck

Centering several buttons WPF

I was writing C# code in winforms. In winForms using this menu (in the picture) I make center several buttons. But I can not find out any way to make center some elements horizontally in WPF.
Use the HorizontalAlignment property. For example:
<StackPanel Orientation="Horizontal" Height="50" HorizontalAlignment="Center">
<Button Width="50" Margin="5"></Button>
<Button Width="50" Margin="5"></Button>
<Button Width="50" Margin="5"></Button>
<Button Width="50" Margin="5"></Button>
</StackPanel>

Align button content

I want the content of a wpf button to be left aligned
I tried the following but the text is still centered inside the button.
<Button >
<StackPanel HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Left" Text="Save"/>
</StackPanel>
</Button>
What do i do?
Found it, it's HorizontalContentAlignment.
:)
You don't need the StackPanel or the TextBlock. All you need is
<Button HorizontalContentAlignment="Left" Content="Save" />
You can align in two way, Horizontal and Vertical
<Button Content="Export" VerticalContentAlignment="Bottom" name="MyBtn1" />
or
<Button Content="Export" HorizontalContentAlignment="Center" name="MyBtn2" />
See the follow image to view the possibilities settings:

Resources