I have a WPF application (C#) thats using a Material Designs PopUpBox for its menu navigation, as per the following:-
<materialDesign:PopupBox Margin="10,0,0,0" PlacementMode="BottomAndAlignLeftEdges" StaysOpen="false" IsEnabled="{Binding IsSystemControlsEnabled}" Style="{DynamicResource template_NavigationMenu}" >
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon Foreground="White" Height="25" Kind="Menu" Width="25"/>
</materialDesign:PopupBox.ToggleContent>
<StackPanel Width="150" >
<Button Command="{Binding ScreenCommand}" CommandParameter="Dashboard" Content="Dashboard" FontSize="12" FontWeight="Medium" Height="20" Name="MenuDashboard" VerticalAlignment="Top" VerticalContentAlignment="Top" />
<Separator/>
<Button Command="{Binding ScreenCommand}" CommandParameter="Encrypt" Content="Encrypt" FontSize="12" FontWeight="Medium" Height="20" Name="MenuEncrypt" VerticalAlignment="Top" VerticalContentAlignment="Top" />
<Separator />
<Button Command="{Binding ScreenCommand}" CommandParameter="Decrypt" Content="Decrypt" FontSize="12" FontWeight="Medium" Height="20" Name="MenuDecrypt" VerticalAlignment="Top" VerticalContentAlignment="Top" />
<Separator />
</StackPanel>
</materialDesign:PopupBox>
Is there a way to cascade this menu and add an extra layer? So for example, if I was to select or hover over the button for Encryption, it would they give me a new popupbox, just to the right, with some new options relating to encryption?
I'm trying to find something like this https://m2.material.io/components/menus (first image) but can't find anything relating to C# / XAML, so looking for some inspiration from the experts...
Any help is greatly appreciated.
Thank you
Related
I want to add a refresh button to my app so that I don't always have to quit the app to clear the data.
I have tried a RefreshRequested, but I can't make it work.
C# code:
private void RefreshButtonClick(object sender, RoutedEventArgs e)
{
RefreshContainer.requestRefresh();
}
<RefreshContainer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" Click="Button_Click_Start" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" Click="Button_Click_Pause" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" Click="Button_Click_Reset" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" Click="Button_Click_Rest" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</RefreshContainer>
I expect the app data to refresh
Refresh Button UWP
I tested your code, the problem is you have not set a scroll-able control as RefreshContainer's content. Base on #Stuart Smith provided document, you could realize refresh feature, before that you need place the above Grid content under the ScrollViewer.
Xaml
<RefreshContainer Name="MyRefreshContainer" RefreshRequested="MyRefreshContainer_RefreshRequested">
<ScrollViewer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</ScrollViewer>
</RefreshContainer>
Code behind
private void RefreshButtonClick(object sender, RoutedEventArgs e)
{
MyRefreshContainer.RequestRefresh();
}
private async void MyRefreshContainer_RefreshRequested(RefreshContainer sender, RefreshRequestedEventArgs args)
{
using (var RefreshCompletionDeferral = args.GetDeferral())
{
// Do some async operation to refresh the content
RefreshCompletionDeferral.Complete();
RefreshCompletionDeferral.Dispose();
}
}
Tomas, I see you've abandoned the refresh button for now, but I wanted to follow up in case you revisit this later or if others run into this issue in the future.
In order for the data to refresh, you'd need to code this in.
“To get fresh content when needed, handle the RefreshRequested event. In the event handler, you'll need code specific to your app to get the fresh content.” https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/pull-to-refresh#handle-a-refresh-request. There's a sample in the doc there too.
You'd typically use data binding for this and the RefreshRequested event would need to edit the bound object.
using (var RefreshCompletionDeferral = args.GetDeferral())
{
await FetchAndInsertItemsAsync(3);
}
In the sample, you'll notice that FetchAndInsertItemsAsync is inserting new items to the backing collection.
There's more info on data binding here: https://learn.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart
I have .xaml items accross three files. In one .xaml I have option to change language at running.
Is there any chance how can I access items from others .xaml to change the language as well?
Changing language of .xaml items in MainWindow.xaml.cs
public partial class MainWindow : Window
{
string strLanguage = "";
Boolean boolInit = true;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Set_Language();
}
private void ddlLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Set_Language();
}
private void Set_Language()
{
if (boolInit == false)
{
strLanguage = "SMS_Vrana.Languages." + ((ComboBoxItem)ddlLanguage.SelectedItem).Name.ToString();
ResourceManager LocRM = new ResourceManager(strLanguage, typeof(MainWindow).Assembly);
lblNumber.Text = LocRM.GetString("strNumber");
lblMessage.Text = LocRM.GetString("strMessage");
btnSend.Content = LocRM.GetString("strSend");
menuItemFile.Header = LocRM.GetString("strMenuFile");
menuItemMainMenu.Header = LocRM.GetString("strMenuMainMenu");
menuItemClose.Header = LocRM.GetString("strMenuClose");
menuItemCheckConnection.Header = LocRM.GetString("strMenuConnection");
}
}
.xaml of Mainwindow.xaml:
<grid>
<Menu DockPanel.Dock="Top" Margin="0,0,0,434">
<MenuItem Header="_File" Name="menuItemFile">
<MenuItem Header="_Main Menu" Click="MenuItem_Click" Name="menuItemMainMenu"/>
<Separator/>
<MenuItem Header="Close" Click="MenuItem_Close" Name="menuItemClose"/>
</MenuItem>
<MenuItem Header="Monitoring" IsEnabled="False">
<MenuItem Header="Ping" IsCheckable="True" Checked="menuPingCheck" Unchecked="menuPingUncheck"/>
<MenuItem Header="GSM" IsCheckable="True" Checked="menuGsmCheck" Unchecked="menuGsmUncheck"/>
</MenuItem>
<MenuItem Header="Check Connection" Click="menuItemCheckConnection_Click" Name="menuItemCheckConnection"/>
<ComboBox x:Name="ddlLanguage" SelectionChanged="ddlLanguage_SelectionChanged" Height="23" Width="80">
<ComboBoxItem IsEnabled="False" IsSelected="True" Content="Language"/>
<ComboBoxItem x:Name="English" Content="English"/>
<ComboBoxItem x:Name="Czech" Content="Cesky"/>
</ComboBox>
<MenuItem Header="_Language" x:Name="menuLangTest" IsEnabled="True" Visibility="Hidden">
<MenuItem Header="Czech" x:Name="menuCzech" Checked="menuItemCzechCheck" Unchecked="menuItemCzechUnche"/>
<MenuItem Header="English" x:Name="menuEng" Checked="menuItemEngCheck" Unchecked="menuItemEngUnche"/>
</MenuItem>
</Menu>
<Ellipse Fill="#000000" Stroke="#000000" Margin="10,0,0,347" x:Name="ellGSM" HorizontalAlignment="Left" Width="38" Height="38" VerticalAlignment="Bottom" Visibility="Hidden"/>
<Ellipse Fill="#000000" Stroke="#000000" Margin="204,0,0,347" Name="ellCol" HorizontalAlignment="Left" Width="38" Height="38" VerticalAlignment="Bottom" Visibility="Hidden"/>
<TextBox x:Name="txtNumber" MaxLength="13" HorizontalAlignment="Left" Height="26" TextWrapping="Wrap" VerticalAlignment="Top" Width="310" Margin="10,153,0,0" PreviewTextInput="txtNumber_PreviewTextInput"/>
<TextBox x:Name="txtMessage" MaxLength="1300" HorizontalAlignment="Left" Height="100" TextWrapping="Wrap" VerticalAlignment="Top" Width="310" Margin="10,250,0,0"/>
<Button x:Name="btnSend" Cursor="Hand" Content="Send!" HorizontalAlignment="Left" VerticalAlignment="Top" Width="310" Margin="10,407,0,0" Height="52" FontSize="36" Click="btnSend_Click"/>
<TextBlock Grid.Column="0" Name="lblNumber" Text="Number" Margin="10,122,213,321" FontSize="16"/>
<TextBlock Grid.Row="0" Grid.Column="0" Name="lblMessage" Text="Message" Margin="10,217,213,224" FontSize="16"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="GSM" VerticalAlignment="Top" Margin="53,46,0,0" Name="txtblockGsm" Visibility="Hidden"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="PING" VerticalAlignment="Top" Margin="172,46,0,0" Name="txtblockPing" Visibility="Hidden"/>
<Image HorizontalAlignment="Left" Name="imgGsm" Height="42" VerticalAlignment="Top" Width="49" Margin="271,40,0,0" Source="C:\Users\lvrabel\source\repos\SMS Vrána\SMS Vrána\Images\GsmGreen.png" Visibility="Hidden"/>
<Label Content="1300" HorizontalAlignment="Left" Margin="287,345,0,0" VerticalAlignment="Top" Height="25" Name="lblLeftCharacters" />
<Label Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="280,84,0,0" Name="lblGsmSignal" Width="40"/>
</grid>
.xaml of Authentication.xaml what I would like to access in MainWindow.xaml.cs for changing language for that items as well. I just would like to change language in whole application and no just for one window.
<Grid Margin="0,-17,0,0">
<Menu DockPanel.Dock="Top" Margin="0,17,0,432">
<MenuItem Header="File" FontSize="16" Name="menuItemFile">
<MenuItem Header="Back on Main Menu" Click="menuItemMainMenuClick"/>
<Separator/>
<MenuItem Header="Close" Click="menuItemCloseClick"/>
</MenuItem>
</Menu>
<Label Content="IP Adress" Name="lblIPAddress" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,210,0,0" Height="36" Width="101" FontSize="16"/>
<Label Content="Login" Name="lblLogin" HorizontalAlignment="Left" Margin="10,279,0,0" VerticalAlignment="Top" Height="31" Width="59" FontSize="16"/>
<Label Content="Password" Name="lblPassword" HorizontalAlignment="Left" Margin="10,343,0,0" VerticalAlignment="Top" Height="31" Width="75" FontSize="16"/>
<TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="292" Margin="10,251,0,0" Name="txtBoxIP" PreviewTextInput="txtBoxIP_PreviewTextInput"/>
<TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="292" Margin="10,315,0,0" Name="txtBoxLogin"/>
<PasswordBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="292" Margin="10,379,0,0" PasswordChar="*" Name="pswBox" Height="23" />
<CheckBox Content="Remember me!" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,413,0,0" Name="CheckBoxRemCredts" Checked="CheckBoxRemCredts_Checked"/>
<Button Content="Login" Cursor="Hand" HorizontalAlignment="Left" Height="34" Margin="10,442,0,0" VerticalAlignment="Top" Width="292" Name="btnLoginAuth" Click="btnLoginAuth_Click" FontSize="18"/>
</Grid>
U can access the xaml code of any xaml until and unless they are in same project and same solution.
U just need to initialize the other xaml you want to use in your xaml.cs file.
For example, I have two xaml files Main.xaml and Login.xaml
So i can use Login view and its element in Main.xaml.cs
Syntax :
Main.xaml.cs
Login login=new Login();
Now you can access any control of Login page provided u give name to every element you use.
eg : login.TextBlockEmail.Text="yourtext";
UPDATED ANSWER :
Hi, I got what you are looking for. Your whole idea is to achieve Localization where all your views associated with the main view shall update.
There are multiple approaches to achieve this, here i am sharing links which may help you :
https://www.codeproject.com/Articles/22967/WPF-Runtime-Localization
https://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files
https://social.msdn.microsoft.com/Forums/vstudio/en-US/4a7f049b-f1b7-4982-874f-f9ecfe3d9140/how-to-change-the-language-in-my-view-wpf?forum=wpf
c# - localization - changing language in wpf app
What you ask for is possible - surely you can get reference to some control in the backend file (.xaml.cs) and then assign it to some variable that is visible to both classes.
However this is better done by using events. You define some event on your main class that should be visible to every window, and then subscribe to it in the code for each window.
I am using the MaterialDesignThemes nuget package along with the Mahapps.Metro package
I have this DialogHost
<material:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False" >
<material:DialogHost.DialogContent>
<StackPanel Margin="16" Orientation="Vertical">
<Label Content="Add custom date" FontSize="16" />
<DatePicker />
<StackPanel Orientation="Horizontal">
<Button Content="ACCEPT" Style="{DynamicResource MaterialDesignFlatButton}" IsDefault="True" Margin="0,8,8,0" Command="material:DialogHost.CloseDialogCommand" CommandParameter="True" />
<Button Content="CANCEL" Style="{DynamicResource MaterialDesignFlatButton}" IsCancel="True" Margin="0,8,8,0" Command="material:DialogHost.CloseDialogCommand" CommandParameter="False" />
</StackPanel>
</StackPanel>
</material:DialogHost.DialogContent>
</material:DialogHost>
That is being openend by this button
<Button MinWidth="120" Margin="10" Style="{StaticResource MaterialDesignRaisedAccentButton}" ToolTip="Add in a new custom date." Command="{x:Static material:DialogHost.OpenDialogCommand}" CommandTarget="{Binding ElementName=PopupAddCustom}" >
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20" Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource fa_plus}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="10,0,0,0" VerticalAlignment="Center" Text="Custom" />
</StackPanel>
</Button>
However when this dialog gets opened the ACCEPT and CANCEL buttons are disabled. So to check if anything was wrong I manually opened this dialog from the my MainWindow constructor like this
this.Loaded += delegate(object sender, RoutedEventArgs args)
{
this.PopupAddCustom.IsOpen = true;
};
When I open the dialog like this the button are in working order, am I missing something obvious here?
The problem was resolved by setting a command target for the buttons like this
CommandTarget="{Binding ElementName=PopupAddCustom}"
To save someone elses time: I had dialog content specified as command parameter and specifying CommandTarget did not help me.
What helps in my case, is to put CommandParameter before Command.
You can achieve that by passing content as resource.
Example:
Before:
<Button
...
Command="{x:Static material:DialogHost.OpenDialogCommand}"
>
<Button.CommandParameter>
<Grid>
** Dialog content **
</Grid>
</Button.CommandParameter>
** Button content **
</Button>
After:
<UserControl.Resources>
<Grid x:Key="MyDialogContent">
** Dialog content **
</Grid>
</UserControl.Resources>
<Button
...
CommandParameter="{StaticResource MyDialogContent}"
Command="{x:Static material:DialogHost.OpenDialogCommand}"
>
** Button content **
</Button>
And dialoghost buttons were not disabled anymore.
I am new to WPF,and have written a simple hello world type application in order to get started. The code I have so far is shown below:
WPF XAXML
<Window x:Name="wndMain" x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ews="clr-namespace:ExtraWindowStyles"
ResizeMode="NoResize"
ews:ExtraWindowStyles.CanMinimize="false"
ews:ExtraWindowStyles.CanMaximize="false"
Title="Hello World" Height="501.492" Width="842.285">
<Grid>
<GroupBox Header="Input Parameters" HorizontalAlignment="Left" Height="173" Margin="10,25,0,0" VerticalAlignment="Top" Width="801" >
<StackPanel Orientation="Horizontal" Margin="0,0,96,0">
<StackPanel Margin="10">
<Label FontWeight="Bold">First Group</Label>
<RadioButton x:Name="opt11">Option 1 - 1</RadioButton>
<RadioButton x:Name="opt12">Option 1 - 2</RadioButton>
<RadioButton x:Name="opt13">Option 1 - 3</RadioButton>
</StackPanel>
<StackPanel Margin="10">
<Label FontWeight="Bold" Content="Second Group"/>
<RadioButton x:Name="opt21" Content="Option 2 - 1"/>
<RadioButton x:Name="opt22" Content="Option 2 - 2"/>
<RadioButton x:Name="opt23" Content="Option 2 - 3"/>
</StackPanel>
</StackPanel>
</GroupBox>
<Separator HorizontalAlignment="Left" Height="80" Margin="17,203,0,0" VerticalAlignment="Top" Width="794"/>
<Button x:Name="btnSubmit" Content="Submit" HorizontalAlignment="Left" Height="34" Margin="632,203,0,0" VerticalAlignment="Top" Width="179" Click="btnExplore_Click" />
<Label Content="Results:" HorizontalAlignment="Left" Height="28" Margin="10,242,0,0" VerticalAlignment="Top" Width="161"/>
<Label Content="My App" HorizontalAlignment="Left" Height="23" Margin="696,439,0,0" VerticalAlignment="Top" Width="130" FontSize="9"/>
<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
Click Here
</Hyperlink>
</TextBlock>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="162" Margin="17,270,0,0" Stroke="Black" VerticalAlignment="Top" Width="794"/>
<Label x:Name="lblResult" Content="" HorizontalAlignment="Left" Height="157" Margin="17,275,0,0" VerticalAlignment="Top" Width="794"/>
</Grid>
</Window>
Code Behind..
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
If I comment out the Hyperlink control XAML (and its related backend code), I am able to select options, click the Submit button etc.
However, if I uncomment the Hyperlink control (and its associated backend code), The only thing that remains clickable, is the Url on the form - what's going on?
Just position your TextBlock and it won't take all space in the window and cover everything :
<TextBlock Width="100" Height="30">
<Hyperlink Background="Red" NavigateUri="http://www.google.com" >
Click Here
</Hyperlink>
</TextBlock>
Because the TextBlock is after submit button in XAML it is over.
You could also set Margin to position the TextBlock
Layout knowledge
Elements in a grid Stretch Horizontally and Vertically if no alignment is set.
Useful tip : If you click on the TextBlock tag, you'll see the extent of the TextBlock in the design view.
Often useful
I have three buttons lying one by one. I want to show top of all button, which i click. So that I have set canvas ZIndex in XAML Code. But I want to do this in Code Behind.
My XAML Output & Code -
<Button Name="Button1" Canvas.ZIndex="3" Content="Button1" Canvas.Top="100" Width="163" Height="58" FontSize="26" Click="Button1_Click" />
<Button Name="Button2" Canvas.ZIndex="2" Content="Button1" Canvas.Top="100" Canvas.Left="130" Width="163" Height="58" FontSize="26" Click="Button2_Click" />
<Button Name="Button3" Canvas.ZIndex="1" Content="Button1" Canvas.Top="100" Canvas.Left="260" Width="163" Height="58" FontSize="26" Click="Button3_Click" />
My XAML Output & Code (Check How the ZIndex was Changed)-
<Button Name="Button1" Canvas.ZIndex="3" Content="Button1" Canvas.Top="100" Width="163" Height="58" FontSize="26" Click="Button1_Click" />
<Button Name="Button2" Canvas.ZIndex="2" Content="Button1" Canvas.Top="100" Canvas.Left="130" Width="163" Height="58" FontSize="26" Click="Button2_Click" />
<Button Name="Button3" Canvas.ZIndex="1" Content="Button1" Canvas.Top="100" Canvas.Left="260" Width="163" Height="58" FontSize="26" Click="Button3_Click" />
How I change the Canvas.ZIndex property in WPF button control in Click Event?
You can set z index in code like this:
Panel.SetZIndex(control name, int index);
An attached property is set from code using by convention the SetPropertyName function.
Panel.SetZIndex(Button2, 0);
Z-index canbe set like this..
Panel.SetZIndex(Button2, 10);