Skip to content

Instantly share code, notes, and snippets.

@ivanjx
Created September 9, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanjx/d2592bcef8cd0261e493536495b405c8 to your computer and use it in GitHub Desktop.
Save ivanjx/d2592bcef8cd0261e493536495b405c8 to your computer and use it in GitHub Desktop.
<Grid>
<!-- Menu list -->
<StackPanel HorizontalAlignment="Left"
VerticalAlignment="Stretch"
Width="48"
Background="Black"
Panel.ZIndex="1">
<Grid Background="Red"
HorizontalAlignment="Left"
Width="48"
Height="48" />
<Grid Background="Green"
HorizontalAlignment="Left"
Width="48"
Height="48" />
<Grid Background="Blue"
HorizontalAlignment="Left"
Width="48"
Height="48" />
</StackPanel>
<!-- Content -->
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="48,0,0,0">
<TextBlock FontSize="20"
Text="this is content" />
</Grid>
</Grid>
public partial class HamburgerMenu : UserControl
{
public static DependencyProperty MenusProperty = DependencyProperty.Register(
nameof(Menus),
typeof(FreezableCollection<HamburgerMenuItem>),
typeof(HamburgerMenu));
public FreezableCollection<HamburgerMenuItem> Menus
{
get => (FreezableCollection<HamburgerMenuItem>)GetValue(MenusProperty);
set => SetValue(MenusProperty, value);
}
public HamburgerMenu()
{
InitializeComponent();
Menus = new FreezableCollection<HamburgerMenuItem>();
}
}
[ContentProperty(nameof(MenuContent))]
public class HamburgerMenuItem : Freezable
{
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
nameof(Title),
typeof(string),
typeof(HamburgerMenuItem),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
nameof(Icon),
typeof(Uri),
typeof(HamburgerMenuItem),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty MenuContentProperty = DependencyProperty.Register(
nameof(MenuContent),
typeof(FrameworkElement),
typeof(HamburgerMenuItem),
new FrameworkPropertyMetadata(null));
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public Uri Icon
{
get => (Uri)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
public FrameworkElement MenuContent
{
get => (FrameworkElement)GetValue(MenuContentProperty);
set => SetValue(MenuContentProperty, value);
}
protected override Freezable CreateInstanceCore()
{
return new HamburgerMenuItem();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment