RibbonSplitButton单击事件

时间:2011-08-10 12:54:48

标签: wpf ribbon

先生们,即使

我正在将一个集合绑定到RibbonSplitButton(基本上,显示3个值:红色,绿色,蓝色)一切正常,除了问题我必须弄清楚选择了哪种颜色(项目):

这是我的代码:

<r:RibbonSplitButton Name="TagEm" 
    LargeImageSource="Images\pencil_32.png"
    Label="Tag"
    ItemsSource="{Binding Path=TagCollection}"
    Click="TagEm_Click">
    <r:RibbonSplitButton.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Descr}" />
        </DataTemplate>
    </r:RibbonSplitButton.ItemTemplate>
</r:RibbonSplitButton>

代码背后:

private void TagEm_Click(object sender, RoutedEventArgs e)
{
}

类似于(Tag)TagEm.Items.CurrentItem;

有人可以给我一个提示吗?

非常感谢提前!

<磷>氮

1 个答案:

答案 0 :(得分:0)

不要使用RibbonSplitButton Click事件。而是使用TextBox MouseLeftButtonUp事件。

XAML:

<r:RibbonSplitButton
    Name="TagEm"
    LargeImageSource="Images\pencil_32.png"     
    Label="Tag"     
    ItemsSource="{Binding Path=TagCollection}">
    <r:RibbonSplitButton.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" />
        </DataTemplate>
    </r:RibbonSplitButton.ItemTemplate>
</r:RibbonSplitButton>

事件处理程序:

private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    Tag clickedTag = (sender as TextBlock).DataContext as Tag;
}