Why is ribbon items not showing on the window? - c#

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>

Related

adding a image to button programmatically with text content [duplicate]

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>

Restyling UWP Toolkit Expander Arrow

I'm trying to restyle the Expander control from the Windows Community Toolkit, changing the default ">" symbol to a filled arrow (kind of like a Play button). Following the accepted answer in this question, I copied the default style from the Community Toolkit github repo, and pasted it into a ResourceDictionary (named CustomStyles.xaml), then changed the FontIcon Glyph property from  to . I've referenced that ResourceDictionary in the Page.Resources section, and then bound the new style to the Expander's HeaderTemplate property with a StaticResource reference. Everything should work, but something is causing it to fail.
The exception being thrown is of no help either, as the error displays the message Failed to assign to property 'Microsoft.Toolkit.Uwp.UI.Controls.HeaderedContentControl.HeaderTemplate'. The text associated with this error code could not be found.
Can someone help with this please?
MainPage.xaml
<Page
x:Class="SharpFTP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SharpFTP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" MinHeight="40" />
</Grid.RowDefinitions>
<StackPanel x:Name="itemsPanel" Grid.Column="0" Grid.Row="0">
<toolkit:Expander Header="Favorites" ExpandDirection="Down" HeaderTemplate="{StaticResource expanderFullArrowStyle}">
</toolkit:Expander>
<TextBlock Text="Favorites" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Connected to " Style="{ThemeResource SubtitleTextBlockStyle}" Foreground="LightGray" />
<TextBlock Text=" 10.3.12.128" Style="{ThemeResource SubtitleTextBlockStyle}" Foreground="White"/>
</StackPanel>
<AppBarSeparator Width="{Binding ActualWidth, ElementName=itemsPanel}" Height="2" Foreground="LightGray" />
</StackPanel>
</Grid>
ResourceDictionary XAML
I've included only the modified portion as the full style is 300 lines long. The full default Expander style can be found here
<FontIcon x:Name="Arrow" Margin="12" FontFamily="Segoe MDL2 Assets" FontSize="12"
Glyph="" RenderTransformOrigin="0.5,0.5">
<FontIcon.RenderTransform>
<RotateTransform />
</FontIcon.RenderTransform>
</FontIcon>
The cause of your error should be a type mismatch.
You have modified the default style of Expender, then expanderFullArrowStyle should not be used on HeaderTemplate. Please try this:
<toolkit:Expander Header="Favorites" ExpandDirection="Down" Style="{StaticResource expanderFullArrowStyle}">
</toolkit:Expander>

WPF Tab Navigation In Children UserControl

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>

Mahapps.Metro Flyout appearing behind Winforms chart

I have been using MahApp.Metro for a few project now, and WinForms charts too, and also combined them.
So nothing new on that front in this project, except :
The placement of the chart.
And this is causing an issue where the Mahapps.Metro Flyout menu i have opens BEHIND the chart. See Screenshot.
Is there any way to solve this? i have searched a bit and found nothing. In CSS it would be a simple z-index setting... but in C# i have no idea.
Any help appreciated.
XAML as requested :
<Controls:MetroWindow x:Name="wdw_MainWindow" x:Class="AdminProgram.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:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:winformchart="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
xmlns:local="clr-namespace:AdminProgram"
mc:Ignorable="d"
Title="MainWindow" Height="600" Width="1024" GlowBrush="{DynamicResource AccentColorBrush}" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" BorderThickness="2,2,0,2" ShowMinButton="False" ShowMaxRestoreButton="False" IsMinButtonEnabled="False" IsMaxRestoreButtonEnabled="False" BorderBrush="#FF7C7C7C" TitleForeground="White">
<Controls:MetroWindow.Flyouts>
<Controls:FlyoutsControl>
<Controls:Flyout x:Name="fyo_Menu" Header="Menu" Width="200" Theme="Accent">
<Grid>
<Controls:Tile x:Name="btn_AddNew" Title="Add New"
Width="150" Height="150" TitleFontSize="20" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0" Click="btn_AddNew_Click" KeepDragging="False" MouseEnter="Tile_MouseEnter" MouseLeave="Tile_MouseLeave" BorderBrush="#FFC89632">
</Controls:Tile>
<Controls:Tile x:Name="btn_ViewAll" Title="View All"
Width="150" Height="150" TitleFontSize="20" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,160,0,0" Padding="0" Click="btn_ViewAll_Click" MouseEnter="Tile_MouseEnter" MouseLeave="Tile_MouseLeave" BorderBrush="#FFC89632" >
</Controls:Tile>
</Grid>
</Controls:Flyout>
</Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>
<GroupBox x:Name="gpb_Home_Stats" Header="Latest information and statistics" Margin="0,50,0,0">
<Grid>
<!--- Winforms Integrated charting -->
<!--Strength bars -->
<WindowsFormsHost x:Name="wfh_Statistics_Strengthometer" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" Width="950" Height="425">
<winformchart:Chart x:Name="chart_Strengthometer" Dock="None">
<winformchart:Chart.Legends>
<winformchart:Legend Docking="Left" TitleSeparator="Line" Title="Coffee count by strength"/>
</winformchart:Chart.Legends>
<winformchart:Chart.Series>
<winformchart:Series Name="Strength" ChartType="Column"/>
</winformchart:Chart.Series>
<winformchart:Chart.ChartAreas>
<winformchart:ChartArea/>
</winformchart:Chart.ChartAreas>
</winformchart:Chart>
</WindowsFormsHost>
</Grid>
</GroupBox>
That's a known issue when mixing WinForms and WPF and is not related to MahApps.Metro. Just search for Airspace here at StackOverflow.

Enabling ContextMenu on a Topmost Window

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.

Categories

Resources