【发布时间】:2017-08-08 16:13:50
【问题描述】:
我想做一个 HamburgerMenu。这里是 XAML。
<SplitView Grid.Row="1" HorizontalAlignment="Left">
<SplitView.Content>
<ListView>
<ItemsControl x:Name="NavItemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock FontFamily="Segoe MDL2 Assets" Text="{Binding Icon}"></TextBlock>
<TextBlock Text="{Binding Content}" Grid.Column="1"></TextBlock>
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ListView>
</SplitView.Content>
</SplitView>
下面是代码:
public class NavItems : INotifyPropertyChanged
{
string _Icon;
public string Icon
{
set
{
_Icon = value;
OnPropertyChanged("Icon");
}
get
{
return _Icon;
}
}
string _Content;
public string Content
{
set
{
_Content = value;
OnPropertyChanged("Content");
}
get
{
return _Content;
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
设置好NavItemsControl的ItemSource后,我可以很方便的绑定Icon或者Content等属性。唯一的问题是我要绑定的点击事件
Button,但我不知道如何绑定它。
我尝试使用delegate绑定click事件,但没有成功,报错。
你能帮帮我吗?
谢谢
【问题讨论】: