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);
Related
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
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've got a custom set of controls:
<Border Height="55" Margin="5,14,5,0" VerticalAlignment="Top" BorderThickness="1" BorderBrush="Black">
<Grid>
<TextBlock x:Name="SubjectNo" Text="1" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="36" Margin="0,1,36,0" d:LayoutOverrides="HorizontalAlignment" />
<TextBlock x:Name="Subject" Text="Subject NAME more " TextWrapping="Wrap" FontSize="24" FontWeight="Bold" Margin="26,0,90,19" d:LayoutOverrides="Height, TopPosition, BottomPosition" />
<TextBlock x:Name="Teacher" Text="BIG NAME HERE" TextWrapping="Wrap" FontSize="14.667" VerticalAlignment="Bottom" Margin="26,0,0,9" HorizontalAlignment="Left" Width="106" Height="17" d:LayoutOverrides="VerticalAlignment" />
<Grid Height="15" VerticalAlignment="Bottom" Margin="133,0,0,10" d:LayoutOverrides="VerticalAlignment">
<TextBlock x:Name="BegTime" Text="12:55 AM" TextWrapping="Wrap" FontSize="13.333" d:LayoutOverrides="Height, TopPosition, BottomPosition" SelectionHighlightColor="White" Margin="8,0,-8,0" />
<TextBlock x:Name="EndTime" Text="12:55 PM" TextWrapping="Wrap" FontSize="13.333" Margin="68,0,-12,0" d:LayoutOverrides="HorizontalAlignment, Height, TopPosition, BottomPosition" />
<TextBlock x:Name="Line" Text="-" TextWrapping="Wrap" FontSize="13.333" Margin="64,0,0,0" d:LayoutOverrides="Height, TopPosition, BottomPosition" />
</Grid>
<Border Margin="281,4,10,6" BorderBrush="Black" BorderThickness="1" d:LayoutOverrides="TopPosition, BottomPosition" HorizontalAlignment="Center" Width="57">
<Grid>
<TextBlock x:Name="RoomNo" Text="1255" TextWrapping="Wrap" FontSize="24" d:LayoutOverrides="HorizontalAlignment, Width, TopPosition, BottomPosition" Margin="2,10,-2,0" />
<TextBlock x:Name="RoomWritten" Text="Room" TextWrapping="Wrap" FontSize="14.667" VerticalAlignment="Top" HorizontalAlignment="Stretch" d:LayoutOverrides="HorizontalAlignment, Width" Margin="9,0,4,0"/>
</Grid>
</Border>
<AppBarButton x:Name="appBarButton" Label="" Margin="158,0" VerticalAlignment="Bottom" Width="32" HorizontalAlignment="Stretch" Icon="Remote" Height="13" d:LayoutOverrides="VerticalAlignment"/>
</Grid>
</Border>
It looks like this
Now I want to add a button like this to make my control show additional info in the bottom, so I want it to expand from the bottom and show additional textblock, like windows 10 notification center does. Than the icon changes and when I press the button again, additional info hides. Can anybody help me?
The type of control you are looking for is called a ToggleButton. It has an IsChecked state property to facilitate the two states for your "open" and "closed". The logic and styling for what is displayed by you when IsChecked is true or false can be controlled via styles.
More information on MSDN: ToggleButton class
I am using a rectangle and putting emotion images in it, and i want to do is if I make the rectangle hidden, the emotion images in it should be hidden.
I am attaching an image for help in it.
Please let me know which property should I use for getting this, in Windows Forms if we use panel, this can be done automatically. But in WPF C#, this is not done automatically.
Here is the code
<Rectangle Grid.ColumnSpan="2" Height="71" HorizontalAlignment="Left" Margin="226,262,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="192" Fill="#B5101010" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="229,266,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="28" Source="/WPFTEST;component/Images/emo/emotion_evilgrin.png" MouseUp="image1_MouseUp_1" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="264,266,0,0" Name="image2" Source="/WPFTEST;component/Images/emo/emotion_grin.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image2_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="34,299,0,0" Name="image4" Source="/WPFTEST;component/Images/emo/emotion_tongue.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image4_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="68,266,0,0" Name="image5" Source="/WPFTEST;component/Images/emo/emotion_suprised.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image5_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="34,266,0,0" Name="image6" Source="/WPFTEST;component/Images/emo/emotion_smile.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image6_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="0,266,0,0" Name="image7" Source="/WPFTEST;component/Images/emo/emotion_happy.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image7_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="0,299,0,0" Name="image8" Source="/WPFTEST;component/Images/emo/emotion_wink.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image8_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="230,299,0,0" Name="image9" Source="/WPFTEST;component/Images/emo/emotion_unhappy.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image9_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="265,299,0,0" Name="image10" Source="/WPFTEST;component/Images/emo/emotion_waii.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image10_MouseUp" Visibility="Hidden" />
I know that it is not under the rectangle tag, but if i add images under rectangle tag then it causes error.
Thanks
Atif
If those icons are part of the "rectangle" which should be an ItemsControl or panel of some sort, the icons will hide if the parent container is hidden (Visibility = Visibility.Hidden/Collapsed).
Edit: The images are not part of the rectangle they are just placed on top using horrible margin abusing code.
There is no relationship between the rectangle and the icons. As i said, the icons need to be added as children of a container. (e.g. ItemsControl with WrapPanel as ItemsPanel) Surely winforms would not hide the icons either if they are not part of an owning container...
If you want to leave your code as is and not have to change those margins you can just bind the Visibility property of the icons to the Visibility property of the rectangle.
Visibility="{Binding Visibility, ElementName=rectangle2}"
I'm new to c# so go easy.
Basically I build a data table ( and I have verified it's not empty) but it doesn't seem to get displayed in my wpf datagrid... I used this example here and applied it:link text
My datagrid remains blank.
Does that example look fine to you guys?
here is my code:
XACML:
<Window x:Class="WpfApplication1.TickerSearch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TickerSearch" Height="468" Width="907">
<Grid Background="#E6000000" Name="_grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="244*" />
<ColumnDefinition Width="37*" />
</Grid.ColumnDefinitions>
<TextBox Height="34" HorizontalAlignment="Left" Margin="26,15,0,0" Name="txtSearchTker" VerticalAlignment="Top" Width="225" Grid.ColumnSpan="2" />
<Button Content="Search" Height="32" HorizontalAlignment="Left" Margin="76,160,0,0" Name="btnSearch" VerticalAlignment="Top" Width="124" Click="btnSearch_Click" />
<ListBox Height="114" HorizontalAlignment="Left" Margin="26,224,0,0" Name="lstResults" VerticalAlignment="Top" Width="225" Visibility="Hidden" Grid.ColumnSpan="2" Background="#FFFFB000" />
<Button Content="Select" Height="32" HorizontalAlignment="Left" Margin="76,366,0,0" Name="btnSelect" VerticalAlignment="Top" Width="124" Visibility="Hidden" />
<Label Content="Start Date: " Height="25" HorizontalAlignment="Left" Margin="22,65,0,0" Name="label1" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<Label Content="End Date:" Height="27" HorizontalAlignment="Left" Margin="22,93,0,0" Name="label2" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<DatePicker Height="22" HorizontalAlignment="Left" Margin="93,65,0,0" Name="dateFrom" VerticalAlignment="Top" Width="138" />
<DatePicker Height="22" HorizontalAlignment="Left" Margin="93,94,0,0" Name="toDate" VerticalAlignment="Top" Width="138" />
<Label Content="Just Today" Height="27" HorizontalAlignment="Left" Margin="22,122,0,0" Name="label3" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<CheckBox Content="CheckBox" Height="17" HorizontalAlignment="Left" Margin="93,127,0,0" Name="chkBoxToday" VerticalAlignment="Top" Width="15" />
<DataGrid AutoGenerateColumns="False" Height="315" HorizontalAlignment="Left" Margin="285,68,0,0" x:Name="_dataGrid" VerticalAlignment="Top" Width="468" ItemsSource="{Binding Path=.}" Background="#C6F7F700"></DataGrid>
</Grid>
c#:
_ds = new DataSet();
DataTable table = yahooFinance.lookupSymbol();
_ds.Tables.Add(table);
_grid.DataContext = _ds.Tables[0];
Change it to ItemsSource="{Binding}".
Also, set AutoGenerateColumns to true. (Or explicitly specify columns)
Without seeing any code, I'd suggest the two most important points are:
setting the DataContext with myGrid.DataContext = myDS.Tables[0];
having your XAML DataGrid include the ItemsSource property:
<dg:DataGrid ItemsSource="{Binding Path=.}"