I try to control my tab navigation. I made a little program to test it but i don't get what i want.
I want to tab in a certain order. And one of the tab focus on a user controle. Once i'm in a user controle i want to tab in another order. And then when all userControl Tab are done go back to my main control.
Because my code is really short i will paste it all.
First my mainWindow.
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel KeyboardNavigation.TabNavigation="Local">
<TextBox Text="0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="5" KeyboardNavigation.TabIndex="5" />
<local:Page1 KeyboardNavigation.TabIndex="3"/>
<TextBox Text="4" KeyboardNavigation.TabIndex="4" />
<TextBox Text="1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="2" KeyboardNavigation.TabIndex="1" />
</StackPanel>
</Window>
Then the Page1 who are the userControl you see with TabIndex="3"
<UserControl x:Class="WpfApp1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel KeyboardNavigation.TabNavigation="Contained">
<TextBox Text="Child 0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="Child 1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="Child 3" KeyboardNavigation.TabIndex="3" />
<TextBox Text="Child 2" KeyboardNavigation.TabIndex="2" />
</StackPanel>
</UserControl>
What i Get as Order when i Tab is
0 1 2 4 5 Child0 Child1 Child2 Child3
What i want is.
0 1 2 Child0 Child1 Child2 Child3 4 5
AnyWay to achieve this? I try to change TabNavigation to Local Container ect... And didn't find a way to make it work.
Remove KeyboardNavigation.TabNavigation="Contained" from the UserControl and try this:
<StackPanel>
<TextBox Text="0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="5" KeyboardNavigation.TabIndex="5" />
<local:Page1 KeyboardNavigation.TabIndex="3" KeyboardNavigation.TabNavigation="Local"/>
<TextBox Text="4" KeyboardNavigation.TabIndex="4" />
<TextBox Text="1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="2" KeyboardNavigation.TabIndex="2" />
</StackPanel>
Related
Cant make button in WPF app with image and text on it. My code is like this:
<Window x:Class="WindowR.One"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WindowR"
mc:Ignorable="d"
Title="One" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock Text="Click Here" />
<Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
</StackPanel>
</Grid>
</Window>
But the text isnt above image..tried lots of tutorials from here..but none of them work properly
StackPanel arranges TextBlock next to Image. Try to use Grid
<Button Width="120" Height="50" >
<Grid>
<Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
<TextBlock Text="Click Here"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
</Button>
I'm developing an app, using .NET Core 3.1. adding reference to Fluent Ribbon but when I write some XAML nothing shows.
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
xmlns:fluent="urn:fluent-ribbon"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<fluent:Ribbon>
<fluent:Ribbon.Menu>
<fluent:Backstage>
<fluent:BackstageTabControl>
<fluent:BackstageTabItem Header="Database">
<WrapPanel Orientation="Horizontal">
<WrapPanel Orientation="Vertical">
<fluent:Button Header="Open Database" Foreground="Black" />
<fluent:Button Header="Save Database" Foreground="Black" />
<fluent:Button Header="Do something" Foreground="Black" />
</WrapPanel>
<fluent:TextBox Header="Database Name" Text="Your Database" Foreground="Black"/>
</WrapPanel>
</fluent:BackstageTabItem>
<fluent:Button x:Name="ExitButton" Header="Exit" />
</fluent:BackstageTabControl>
</fluent:Backstage>
</fluent:Ribbon.Menu>
</fluent:Ribbon>
</Grid>
</Window>
Any idea what I'm doing wrong?
You don't seem to have added any items to the Ribbon. You have only set the Menu property.
Try to add a RibbonTabItem to the Ribbon as they do in this basic setup:
<Fluent:RibbonWindow x:Class="MyFirstRibbonProject.MyFirstWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Fluent="urn:fluent-ribbon"
Title="My first RibbonWindow"
Width="800"
Height="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Fluent:Ribbon Grid.Row="0">
<!--Backstage-->
<Fluent:Ribbon.Menu>
<Fluent:Backstage>
</Fluent:Backstage>
</Fluent:Ribbon.Menu>
<!--Tabs-->
<Fluent:RibbonTabItem Header="Home">
<Fluent:RibbonGroupBox Header="Group">
<Fluent:Button Header="Green"
Icon="Resource-Path to your small icon for this button"
LargeIcon="Resource-Path to your large icon for this button" />
<Fluent:Button Header="Grey"
Icon="Resource-Path to your small icon for this button"
LargeIcon="Resource-Path to your large icon for this button" />
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>
</Fluent:Ribbon>
<Grid Grid.Row="1">
<TextBlock>My first window containing a Ribbon and something else.</TextBlock>
</Grid>
</Grid>
</Fluent:RibbonWindow>
I have a desktop application I am building in C# with XAML. I am having troube with the XAML side of things, and how its displayed on the preview compared to the actual program view.
I have tried putting the elements I am using into a grid, a stackPanel but it still has the same issue. Here is what the program should look like:
And how it actually appears in the program:
<Page x:Class="project.PayFees"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:mosque"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Pay Fees">
<Grid>
<Grid>
<Label Margin="67,90,641,328" Content="Amount Paid"/>
<Button Command="{Binding PayFees}" Content="Pay Fees" Margin="584,405,10,10"
RenderTransformOrigin="1.172,-3.328"/>
<Label Margin="67,62,691,360" Content="Date" RenderTransformOrigin="0.684,-0.03"/>
<TextBox x:Name="StudentID" Text="{Binding StudentID}" Width="130"
Margin="159,126,511,290" RenderTransformOrigin="-0.285,-6.056" />
<Label Content="Student ID" RenderTransformOrigin="3.77,3.251" Margin="67,126,663,292"/>
<TextBox x:Name="AmountPaid" Text="{Binding AmountPaid}" Width="130"
Margin="159,90,511,328" RenderTransformOrigin="0.039,0.004"/>
<TextBox Text="{Binding Date}" HorizontalAlignment="Left" Margin="159,52,0,0"
VerticalAlignment="Top" RenderTransformOrigin="2.704,6.1" Width="130" Height="32"/>
<Button Content="Load Student" HorizontalAlignment="Left" Margin="306,136,0,0"
VerticalAlignment="Top" Width="86" Height="22" Click="Button_Click"/>
<Label x:Name="studentName" Content="" HorizontalAlignment="Left" Margin="159,165,0,0"
VerticalAlignment="Top" Width="130"/>
</Grid>
</Grid>
This is my XAML code.
I can't figure out why this is happening - any advice is appreciated.
Hi i have a wpf user control and wpf textbox control in a page, when i pressed on Tab in keyboard it's not going to next control which is a normal textbox. i had set the property Tabstop to true but nothing worked...
I have not created any special property for tab index in user control.
<StackPanel Orientation="Vertical">
//(User Control)
<controls:UserControl x:Name="txt_Name" Header="Name"/>
(Normal TextBox Control)
<StackPanel Orientation="Vertical" Margin="10">
<Label Content="Size" VerticalAlignment="Top" />
//(Normal TextBox Control)
<TextBox Name="txt_sizeofFacility"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label Content="Age" VerticalAlignment="Top" />
//(Normal TextBox Control)
<TextBox Name="txt_ageofFacility"/>
</StackPanel>
//(User Control)
<controls:UserControl x:Name="txt_primaryActivity" Header="Primary Activity"/>
</StackPanel>
This is my code:
<StackPanel Orientation="Vertical">
<!--//(User Control)-->
<controls:UserControl1 x:Name="txt_Name" />
<!--(Normal TextBox Control)-->
<StackPanel Orientation="Vertical" Margin="10">
<Label Content="Size" VerticalAlignment="Top" />
<!--//(Normal TextBox Control)-->
<TextBox Name="txt_sizeofFacility"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label Content="Age" VerticalAlignment="Top" />
<!--//(Normal TextBox Control)-->
<TextBox Name="txt_ageofFacility"/>
</StackPanel>
<!--//(User Control)-->
<controls:UserControl1 x:Name="txt_primaryActivity" />
</StackPanel>
And this is the UserControl:
<UserControl x:Class="TabIndex.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBox x:Name="test"></TextBox>
</Grid>
I can reproduce. Tab works even after setting focuse manually in each textbox
I had the same problem and found out that you can set the property below on the user control and that worked for me.
KeyboardNavigation.TabNavigation="Local"
I have a window with Topmost="True".
<Window ... bunch of code ....
Topmost="True" >
Doing this now effectively disables all context menus on the form. The menus are defined in the XAML, like this:
<StackPanel Width="120" Height="50" MouseMove="Drag_MouseMove">
<Image Source="{Binding" />
<TextBlock Text={Binding}" />
<StackPanel.ContextMenu>
<ContextMenu Name="myMenu" StaysOpen="True">
... bunch of code ...
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
Is there a way to re-enable context menus? I'm also willing to consider alternatives to Topmost="True".
I can't reproduce your problem. I've created a new project using this near-code to yours and context menu does show.
Maybe the problem comes from something else? like the bindings? (talking from experience)
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Topmost="True">
<Grid>
<StackPanel Width="120" Height="50" Background="Gray">
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<TextBlock Text="yo" />
<StackPanel.ContextMenu>
<ContextMenu Name="myMenu" StaysOpen="True">
<MenuItem Header="hello" />
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
</Grid>
</Window>
I suspect that the menu is showing just fine. However, the menu is not a top level item so it ends up behind your topmost MainWindow. I've got the same problem and have not yet found the answer as to how to make sure that the menu always shows.