开发者

Attached behaviors and styles

开发者 https://www.devze.com 2023-03-06 18:55 出处:网络
I use an attached behavior that allows a DoubleClick event to be wired to a command in a view model, as in the binding below:

I use an attached behavior that allows a DoubleClick event to be wired to a command in a view model, as in the binding below:

<ListBox Style="{StaticResource MasterListBoxStyle}"
    b:SelectionBehavior.DoubleClickCommand="{Binding开发者_如何学Go EditCommand}" 
     >

I need multiple list boxes for a presentation, all of which will need a DoubleClick wired to an EditCommand.

Can I push this behavior into my MasterListBoxStyle? How?

Cheers,

Berryl

<Style x:Key="MasterListBoxStyle" TargetType="ListBox">
    <Setter Property="ItemsSource" Value="{Binding MasterVm.AllDetailVms}" />
    <Setter Property="ItemContainerStyle" Value="{StaticResource MasterListingRowStyle}" />
    <Setter Property="IsSynchronizedWithCurrentItem" Value="True" />
    <Setter Property="AlternationCount" Value="2" />
</Style>


You should be able to add a simple Setter like so in WPF:

<Setter Property="b:SelectionBehavior.DoubleClickCommand" Value="{Binding EditCommand}" />

Assuming the b xmlns is defined in the XAML file that contains your Style.

This won't work in Silverlight though, since Bindings are not supported in Setters. This is something Microsoft is fixing in Silverlight 5.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号