1
定义的按钮,我有如下模板defiend:点击里面的DataTemplate
<Window.Resources>
<DataTemplate x:Key="TemplateDetailView">
<Expander x:Name="exp" IsExpanded="True" FontSize="13" FontWeight="SemiBold">
<Expander.Header>
<TextBlock Foreground="{DynamicResource BlackColorBrush}">
<TextBlock.Text>
<MultiBinding StringFormat="{} {0} {1}">
<Binding Path="persons.Count"/>
<Binding Path="DisplayText"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Expander.Header>
<ListBox x:Name="lst" ItemsSource="{Binding persons}" Grid.Row="1" BorderThickness="0" Foreground="{DynamicResource BlackColorBrush}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="stretch"/>
<Setter Property="Background" Value="Transparent" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border DataContext="{Binding}" BorderThickness="2" Margin="0,0,0,-1" BorderBrush="{DynamicResource NormalBorderBrush}" Visibility="{Binding IsVisibility}">
<DockPanel Margin="15,5" Background="Transparent">
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Background="Transparent">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center" Tag="{Binding}" Padding="4,0" Style="{DynamicResource CheckBoxStyleDetailedViewStyle}" Checked="CheckBox_Checked" IsChecked="{Binding Acknowledged}" Height="30" Margin="3,5,3,3" Width="Auto"/>
</StackPanel> <ScrollViewer CanContentScroll="True" MinHeight="25" DockPanel.Dock="Left" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<ItemsControl ScrollViewer.CanContentScroll="True" DataContext="{Binding}" ItemsSource="{Binding AlertActionsDefinition.Children}" x:Name="lstButton" ButtonBase.Click="lstButton_Click">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent" >
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate >
<DataTemplate>
<Button Click="lstButton_Click" Content="{Binding Text}" Tag="{Binding}" Padding="4,0" IsEnabled="{Binding Visible}" Visibility="{Binding Visibility}" Height="30" Margin="3,5,3,3"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer> </StackPanel>
<Grid Width="700">
<Grid.RowDefinitions>
<RowDefinition Height="3"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3"/>
<RowDefinition Height="*"/>
<RowDefinition Height="3"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Text}" Grid.Row="1" FontWeight="Bold" FontSize="14"/>
<TextBlock Text="{Binding Description}" Grid.Row="3" FontSize="13"/>
</Grid>
</DockPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=lst,Path=Items.Count}" Value="0">
<Setter Property="Visibility" Value="Collapsed" TargetName="exp"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox x:Name="listBox" ItemTemplate="{DynamicResource TemplateShortView}" ItemsSource="{Binding}" BorderThickness="0">
</ListBox>
</Grid>
列表框被绑定到一类人。最初列表框中加载了短视图,然后加载到上面定义的详细视图模板。我面临的问题是模板内按钮上的点击事件。点击不会被解雇,有时候需要两到三次点击来提高事件。
任何人都可以帮我找出来吗?