how to add two or more buttons in dock panel? - c#

I am using WPF and DevExpress. I want to add two buttons in dock panel. As I added 2nd button it said: Content is set more than once. Why is it so ? Did I made any mistake or is dock panel doesn't allow this.
<dxdo:DockLayoutManager Margin="0,-3,-156,0" HorizontalAlignment="Right" VerticalAlignment="Top" Background="White" Height="243" Width="109">
<dxdo:LayoutGroup Caption="LayoutRoot" Margin="0,0,0,172">
<dxdo:LayoutGroup Orientation="Vertical">
<dxdo:LayoutPanel x:Name="Panel1" ShowCloseButton="False" ShowMaximizeButton="False" ShowPinButton="False" ShowRestoreButton="False" ShowControlBox="False" AllowDock="False" AllowDrag="False" AllowFloat="False" AllowHide="False" AllowClose="False" AllowActivate="False" AllowMinimize="False" AllowMaximize="False">
<Button x:Name="ToggleButton1" Content="New" Click="ToggleButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="Delete Focused Row"
Click="DeleteButton_Click33"
Grid.Column="1" />
</dxdo:LayoutPanel>
<dxdo:LayoutPanel x:Name="Panel2" ShowCloseButton="False" ShowMaximizeButton="False" ShowPinButton="False" ShowRestoreButton="False" ShowControlBox="False" AllowDock="False" AllowDrag="False" AllowFloat="False" AllowHide="False" AllowClose="False" AllowActivate="False" AllowMinimize="False" AllowMaximize="False">
<Button x:Name="ToggleButton2" Content="Close" Click="ToggleButton2_Click" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</dxdo:LayoutPanel>
</dxdo:LayoutGroup>
</dxdo:LayoutGroup>
</dxdo:DockLayoutManager>

You can place more than one control into the LayoutPanel.Content property. Just wrap your buttons into panel:
<dxdo:LayoutPanel ... >
<StackPanel Orientation="Vertical">
<Button x:Name="button1" ... />
<Button x:Name="button2" ... />
</StackPanel>
</dxdo:LayoutPanel>
Related example: How to build a layout of controls within LayoutPanels

Related

Using MaterialDesignThemes DrawerHost

Please could someone assist me in trying to figure this out.
I have created a menu on a WPF page called DashView.xaml
this menu has buttons on it going down and I would like to know how to get the BottomDrawerContent to be visible once I click on a button.
Below I have given the code that is in DashView.xaml
<materialDesign:DialogHost x:Name="hostSales" >
<materialDesign:DrawerHost x:Name="SalesDrawerHost" Content="Sales" Foreground="GhostWhite"
FontWeight="Bold" FontSize="22" BottomDrawerCloseOnClickAway="True"
Cursor="Hand" Width="200" Height="30" ToggleButton.Checked="chkSalesBt1">
<materialDesign:DrawerHost.BottomDrawerContent x:Uid="dashSalesBt1">
<StackPanel x:Name="stkSalesBt1">
<Button Content="Record Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
<Button Content="Recent Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
</StackPanel>
</materialDesign:DrawerHost.BottomDrawerContent>
</materialDesign:DrawerHost>
</materialDesign:DialogHost>
I do have a class called DashClass.cs
Just not sure what I am meant to put in it or how I am meant to get the execution to show the BottomDrawerContent
Yout need a tooglebutton:
<ToggleButton
x:Name="menuToggler"
Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />`
and in the DrawerHost use IsLeftDrawerOpen
<materialDesign:DrawerHost
x:Name="SalesDrawerHost"
Content="Sales"
Foreground="GhostWhite"
FontWeight="Bold"
FontSize="22"
BottomDrawerCloseOnClickAway="True"
Cursor="Hand"
Width="200"
Height="30"
IsBottomDrawerOpen="{Binding ElementName=menuToggler, Path=IsChecked}">
<materialDesign:DrawerHost.BottomDrawerContent x:Uid="dashSalesBt1">
<StackPanel x:Name="stkSalesBt1">
<Button Content="Record Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
<Button Content="Recent Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
</StackPanel>
</materialDesign:DrawerHost.BottomDrawerContent>
</materialDesign:DrawerHost>

custom panel between wrap panel and grid wpf

i want a some panel between wrap panel and grid.this panel must resize children but if a child get to minimum width get it to next row(like wrap panel)
if there is no minwidth property for children act like grid.
You are looking for GridExtra
There are so much details in GridExtra
You can define your grid column and rows and fill them with this command ge:GridEx.AutoFillChildren="True"
Sample code
<Grid ge:GridEx.ColumnDefinition="*, *"
ge:GridEx.RowDefinition="Auto, Auto, Auto"
ge:GridEx.AutoFillChildren="True"
ShowGridLines="True">
<TextBlock Text="Name:" />
<TextBox VerticalAlignment="Top" Margin="5"/>
<TextBlock Text="Age:" />
<TextBox VerticalAlignment="Top" Margin="5"/>
<Button ge:GridEx.Area="2, 1, 1, 1"
Margin="5" Width="60"
HorizontalAlignment="Right"
Content="OK" />
</Grid>

The objects inside the xaml form are being scrambled (resized or hidden) after resizing main window?

I have a problem in resizing the main window of my app.xaml form: after resizing it, the objects (buttons,combo boxes, textboxes, etc) inside the form are being resized, hidden or moved to another place in the form. I just want to resize the main window not the other objects. in the other words, I want to unlink these two (main window & other objects) from each other. after doing that, I can resize main window and then, manually move the objects to their new place in the form. the code of the form is given below.
<Window x:Class="WPFClient.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="550" Width="834" MaxHeight="550" MaxWidth="834" MinHeight="550" MinWidth="834">
<Grid>
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="LightSlateGray" Offset="0"/>
<GradientStop Color="White" Offset="0.5"/>
<GradientStop Color="LightSlateGray" Offset="0.9"/>
</LinearGradientBrush>
</Grid.Background>
<Label x:Name="loginLabelUName" Height="25" HorizontalAlignment="Left" Margin="179,200,0,0" VerticalAlignment="Top" Width="70">User Name:
</Label>
<TextBox x:Name="loginTxtBoxUName" Height="23" Margin="277,200,313,0" VerticalAlignment="Top" />
<Label x:Name="loginLabelIP" HorizontalAlignment="Left" Margin="179,232,0,255" Width="70">Service IP:</Label>
<TextBox x:Name="loginTxtBoxIP" Margin="277,232,313,0" Text="41.235.135.104" Height="23" VerticalAlignment="Top" />
<Button x:Name="loginButtonConnect" Background="Transparent" Margin="277,0,313,222" Click="buttonConnect_Click" Height="23" VerticalAlignment="Bottom">Connect</Button>
<Label x:Name="loginLabelStatus" Height="44" VerticalAlignment="Bottom" FontFamily="Jokerman" FontSize="20" Foreground="White" HorizontalAlignment="Right" Width="167" Margin="0,0,40,71">Offline</Label>
<ComboBox x:Name="loginComboBoxImgs" HorizontalAlignment="Right" Margin="0,200,197,222" Width="98" Background="Transparent" />
<Label x:Name="loginLabelTitle" Height="57" FontFamily="Jokerman" FontSize="25" Foreground="White" Margin="16,16,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="293">WCF / WPF Chat App.</Label>
<Polyline x:Name="loginPolyLine" StrokeThickness="2" Stroke="White" Points="140,90 140,300 700,300 700,90 140,90" Margin="-9,42,116,165" />
<ListBox x:Name="chatListBoxMsgs" Margin="10,62,167,84" />
<ListBox x:Name="chatListBoxNames" HorizontalAlignment="Right" Margin="0,62,10,84" Width="139" />
<CheckBox x:Name="chatCheckBoxWhisper" Height="15" HorizontalAlignment="Right" Margin="0,37,10,0" VerticalAlignment="Top" Width="120" Foreground="White" FontSize="12">Whisper Mode</CheckBox>
<TextBox x:Name="chatTxtBoxType" Height="39" Margin="10,0,313,9" VerticalAlignment="Bottom" />
<Button x:Name="chatButtonSend" Click="chatButtonSend_Click" Height="39" Margin="0,0,167,9" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="136">Send</Button>
<Button x:Name="chatButtonDisconnect" Click="chatButtonDisconnect_Click" Height="39" HorizontalAlignment="Right" Margin="0,0,10,9" VerticalAlignment="Bottom" Width="139">Disconnect</Button>
<Image x:Name="chatCurrentImage" HorizontalAlignment="Left" Margin="10,0,0,0" Stretch="Fill" Width="60" Height="70" VerticalAlignment="Top" />
<Label x:Name="chatLabelCurrentUName" Height="23" HorizontalAlignment="Left" Margin="87,10,0,0" VerticalAlignment="Top" Width="85" Foreground="White"></Label>
<Label x:Name="chatLabelCurrentStatus" Height="23" Margin="87,37,0,0" VerticalAlignment="Top" Foreground="Green" HorizontalAlignment="Left" Width="85"></Label>
<Label x:Name="chatLabelWritingMsg" Height="30" Margin="10,0,167,49" VerticalAlignment="Bottom" Foreground="Gray"></Label>
<Button x:Name="chatButtonSendFile" Click="chatButtonSendFile_Click" Background="Transparent" Height="23" Margin="270,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="105">Send File</Button>
<Label x:Name="chatLabelSendFileStatus" Height="28" Margin="270,32,316,0" VerticalAlignment="Top"></Label>
<Button x:Name="chatButtonOpenReceived" Click="chatButtonOpenReceived_Click" Background="Transparent" Height="23" Margin="382,10,313,0" VerticalAlignment="Top">Open Received Files</Button>
</Grid>
</Window>
The reason why this is occurring is because you are explicitly setting Margin properties on your elements.
Margin="277,232,313,0"
These margins are relative to the parent Grid. So the code above says:
Place the element 277 from the left, 232 from the top, 313 from the right and 0 from the bottom.
Therefore, when the Grid gets resized, these margins will be recalculated, and thus, screw up the positioning of the elements.
To combat this, you should look into using relative positioning. There is already an answer to this question here.
I found a simple solution.when I select an object like button or ..., a small link icon(similar to above Hyperlink icon) appears on each edge of the object (or on grids around it). by clicking on these icons, you can change them into Unlinked or Linked situation. now when you want to resize the main window, you should do the following:
1. move all the objects to the new place you want in the form.
2. select the objects one after another and click on link icon at the side that you want to decrease the main window's width or height from that side.for example, if you want to decrease the width/height of the window from right/down side, you should unlink every "right/down" side link icon.
3. resize the width or height of main window by dragging its edge according to the 2nd step example. you can see that resizing window does not affect other objects at all.

How do I place a text over a image in a button in WinRT

I want to create a button using a image as background and on top of the background I want to place my text.
I tried something like this:
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" />
</StackPanel>
</Button>
The text will not be centered correctly.
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Label Padding="0">My Button Text</Label>
</StackPanel>
</Button>
The control Label doesn't exists.
How do I center correctly my text on the image in my first attempt?
Do you know a better way?
You should use a grid instade the stackpanel. Try something like this:
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>

How do you use StackPanel.FindName in WPF?

I have a stack panel with a set of four image buttons inside of it. When I try to search by the name of the image button it comes back null. What is wrong with my code?
XAML:
<StackPanel x:Name="swatchClearStackPanel" Orientation="Vertical" Grid.Column="1" Grid.Row="2" Margin="0,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<imgbutton:ImageButton x:Name="ClearSwatchColor1" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,8,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click" />
<imgbutton:ImageButton x:Name="ClearSwatchColor2" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,18,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
<imgbutton:ImageButton x:Name="ClearSwatchColor3" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,18,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
<imgbutton:ImageButton x:Name="ClearSwatchColor4" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,20,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
</StackPanel>
And the C#:
EDIT: Note: The button name is hard coded to show that it cannot find it, the end result will be a variable as its one method that several buttons will reference. This code triggers after the UI has loaded. (The user clicks a button and this code runs. Same window, same everything.)
var swatchClearButton = swatchClearStackPanel.FindName("ClearSwatchColor1");

Categories

Resources