Creating a hamburger submenu - wpf

I'm trying to create a hamburger menu with subitems. I'm using this sample from
https://github.com/alicanerdogan/HamburgerMenu and modified it a bit. But my subitems do not appear on the menu. Can you please advise what I'm doing wrong?
<Window
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:hamburgerMenu="clr-namespace:HamburgerMenu;assembly=HamburgerMenu" x:Class="HamburgerMenuDemo.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" WindowStyle="None" AllowsTransparency="True" x:Name="This">
<Grid>
<hamburgerMenu:HamburgerMenu Background="Blue" MenuIconColor="White" SelectionIndicatorColor="White" MenuItemForeground="White" HorizontalAlignment="Left" Margin="0,10,0,-10">
<hamburgerMenu:HamburgerMenu.Content>
<hamburgerMenu:HamburgerMenuItem Icon="Assets/home.png" Text="Home" SelectionCommand="{Binding ElementName=This}"/>
<hamburgerMenu:HamburgerMenuItem Icon="Assets/search.png" Text="Search"/>
<hamburgerMenu:HamburgerMenuItem Icon="Assets/favorite.png" Text="Likes"/>
<hamburgerMenu:HamburgerMenuItem Icon="Assets/list.png" Text="Lists"/>
<hamburgerMenu:HamburgerMenuItem Icon="Assets/person.png" Text="Profile" >
<hamburgerMenu:HamburgerMenuItem.Content>
<hamburgerMenu:HamburgerMenuItem SelectionIndicatorColor="Red" Text="1"/>
<hamburgerMenu:HamburgerMenuItem SelectionIndicatorColor="Red" Text="2"/>
<hamburgerMenu:HamburgerMenuItem SelectionIndicatorColor="Red" Text="3"/>
</hamburgerMenu:HamburgerMenuItem.Content>
</hamburgerMenu:HamburgerMenuItem>
</hamburgerMenu:HamburgerMenu.Content>
</hamburgerMenu:HamburgerMenu>
</Grid>
</Window>

Related

Wpf textbox cannot enter numbers and letters

The keyboard cannot enter English and numbers
window style
I have previously set a prohibition on the use of input methods " xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"
input:InputMethod.IsInputMethodEnabled="False"
But now it’s deleted and you can’t enter numbers and English
<Window
x:Class="WS_StationManagerPlugin.Forms.FrmMPTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cr_utilitywpf="clr-namespace:CR_UtilityWPF;assembly=CR_UtilityWPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WS_StationManagerPlugin.Forms"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="FrmTbale"
Width="800"
Height="600"
Loaded="Window_Loaded"
mc:Ignorable="d">
<TextBox
x:Name="tbxCurrentPage"
Width="30"
Margin="5,0,5,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="#002C41"
Foreground="#fff"
KeyDown="tbxCurrentPage_KeyDown"
PreviewTextInput="tbxCurrentPage_PreviewTextInput"
TextAlignment="Center">
<TextBox.ToolTip>
<ToolTip Content="当前页" />
</TextBox.ToolTip>
</TextBox>
</Window>

Bing maps WPF add location markers

I have a pushpin on my map, but when I click and drag the map the pushpin stays on the same spot on the screen and doesn't move with the map. How do I put the pushpin on a specific location (coordinates) and have it stay there?
Here is my XAML code:
<Window x:Class="WPFKiosk.MapWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFKiosk"
mc:Ignorable="d"
Title="MapWindow" Height="910" Width="1080" WindowStyle="None" ResizeMode="NoResize">
<!-- -->
<Grid Width="1080" Height="915">
<!-- <Image HorizontalAlignment="Left" Height="644" Margin="20,64,-35,0" VerticalAlignment="Top" Width="1095" Source="Images/map.png"/> -->
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road"/>
<m:Pushpin Location="28,-81"
/>
<Image HorizontalAlignment="Left" Height="100" Margin="510,740,0,0" VerticalAlignment="Top" Width="100" Source="Images/iTO Back Arrow.png" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
</Grid>
</Window>
The Pushpin is not "on the map".
It should look like this:
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road">
<m:Pushpin Location="28,-81"/>
</m:Map>

How do I make sure WPF sub-menuitems don't go out of my main window in restore mode?

How do I make sure my sub menu-items stay within the main window like below in restore mode?
Here is a small portion of my code
<Window x:Name="Main Window" x:Class="WpfApplication1.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:WpfApplication1"
mc:Ignorable="d"
Icon="Notepad.ico"
Title="Home" Height="350" Width="860.142">
<Grid>
<Menu x:Name="menu" HorizontalAlignment="Left" Height="22" VerticalAlignment="Top" Width="852" Background="#FFA9D1F4">
<MenuItem Header="_File">
<MenuItem Header="New" Command="New"/>
</MenuItem>
</Menu>
</Grid>
</Window>
Another app.
Note: it may run fine on some computers as pointed out by #G K.

Can I use a resource declared in its own XXX.Resources?

I've a Window, in which I declare one Resource, I was hopping to be able to use it in the window itself, but I'm not sure this is possible?
<dx:ThemedWindow x:Class="SomeWindow"
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:dxco="http://schemas.devexpress.com/winfx/2008/xaml/controls"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:frameworkExtensions="clr-namespace:SomeNamespace.FrameworkExtensions"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" ContentTemplate="{StaticResource dataTemplate}" >
<dx:ThemedWindow.Resources>
<frameworkExtensions:ConventionBasedDataTemplateSelector x:Key="dataTemplate"/>
</dx:ThemedWindow.Resources>
[...]
</dx:ThemedWindow>
Here by example it's for a custom DataTemplate.
How should I do this? Because currently Visual Studio is warning me that it can't find "dataTemplate"
Your problem is because you're trying to use a resource before it's there.
Let's consider a simple example.
If you did:
<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="200" Width="400"
>
<Window.Resources>
<SolidColorBrush x:Key="TestResourceBrush" Color="Blue"/>
</Window.Resources>
<Window.Background>
<StaticResource ResourceKey="TestResourceBrush"/>
</Window.Background>
<Grid>
</Grid>
</Window>
Then you see no error and the background of the window turns blue.
If you instead do:
<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="200" Width="400"
Background="{StaticResource TestResourceBrush}"
>
<Window.Resources>
<SolidColorBrush x:Key="TestResourceBrush" Color="Blue"/>
</Window.Resources>
<Grid>
</Grid>
</Window>
Then that will error, saying it can't resolve the resource.
If you made that a DynamicResource, then that works ok.
<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="200" Width="400"
Background="{DynamicResource TestResourceBrush}"
>
<Window.Resources>
<SolidColorBrush x:Key="TestResourceBrush" Color="Blue"/>
</Window.Resources>
<Grid>
</Grid>
</Window>
The way resources work is that the control looks for the resource in itsself, then in the parent then all the way up the visual tree until it hits the application. see here
so if you had the resource declared on a listview then the panel it is contained within can't use the resource but the list view can.
i suspect the issue you're having is that the template doesn't exist yet because you haven't compiled your code. because wpf is so flexible the designer actually has to run the code to see how it works so if your code hasn't been compiled or has changed since the last compilation the designer can't see the changes.
failing that it may just be order of execution, ie your consuming your template in an attribute but creating it in a child element, in this case move the contentTemplate to an element below the resources element and you should have access to it.
ie
<dx:ThemedWindow.Resources>
<frameworkExtensions:ConventionBasedDataTemplateSelector x:Key="dataTemplate"/>
</dx:ThemedWindow.Resources>
<dx:ThemedWindow.ContentTemplate>
<StaticResource ResourceKey="dataTemplate"/>
</dx:ThemedWindow.ContentTemplate>

WPF Adding UserControl to RadRibbonTab

I'm learning to use WPF.
I'm trying to make RadRibonTab in one file and it's content in the other, however i'm unable to do that.
My parent UserControl:
<UserControl x:Class="TelerikTotorial2.RibbonBar.RibonBarView"
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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:historyTab="clr-namespace:TelerikTotorial2.RibbonBar.History"
mc:Ignorable="d"
>
<telerik:RadRichTextBoxRibbonUI ApplicationButtonContent="File" CollapseThresholdSize="50,50" VerticalAlignment="Top" Margin="0,0,0,-0.2">
<telerik:RadRibbonTab Header="History" HorizontalAlignment="Left" Margin="0" Width="107.2">
<historyTab:HistoryTabView/>
</telerik:RadRibbonTab>
</telerik:RadRichTextBoxRibbonUI>
</UserControl>
UserControl which I try to add
<UserControl x:Class="TelerikTotorial2.RibbonBar.History.HistoryTabView"
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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:history="clr-namespace:TelerikTotorial2.RibbonBar.History"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<telerik:RadRibbonGroup Header="Tools">
<telerik:RadRibbonButton Text="View" Size="Large"/>
</telerik:RadRibbonGroup></UserControl>
However I get exception "InvalidOperationException: Specified element is already the logical child of another element.".
If i replace <historyTab:HistoryTabView/> with
<telerik:RadRibbonGroup Header="Tools">
<telerik:RadRibbonButton Text="View" Size="Large"/>
</telerik:RadRibbonGroup>
then everything is working, however I want to have this code in separate files. Perhaps someone can explain what I am doing wrong? Perhaps it isn't possible to add UserControl to other UserControl?

Resources