如何在WPF中“点击”控件?

时间:2009-06-12 18:36:30

标签: wpf .net-3.5 styles

我有一个订单输入表单,其中ListBox包含订单项列表。我有我的项目模板,其中一个值是我的每个项目中的ComboBox

现在,除了采购订单之外,我的表单还可以创建Credit备忘录,但是当我创建贷记凭证时,我想在列表框中添加“Credit Memo”字样,但TextBlock涵盖了我的两个订单项中的ComboBox。我想将点击事件通过TextBlock传递给ComboBox,但我不知道该怎么做。

这就是我所拥有的,(也许我在这完全错了,我有点像WPF的菜鸟)

<ListBox SelectionMode="Single" Grid.Row="2" 
         ItemsSource="{Binding Path=LineItems}" HorizontalContentAlignment="Stretch" 
         IsSynchronizedWithCurrentItem="True" Background="#66FFFFFF">
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="Background" Value="WhiteSmoke"/>
            <Setter Property="BorderThickness" Value="1" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsPartBackOrder}" Value="True">
                    <Setter Property="Background" Value="Orange" />
                </DataTrigger>                       
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate DataType="{x:Type Entities:SalesOrderLineItem}" >
            <OrderEntry:SalesOrderLineItemCreate DataContext="{Binding}" DeleteSalesOrderLineItem="DeleteSalesOrderLineItem" Margin="0,3,3,0" >
                <OrderEntry:SalesOrderLineItemCreate.Resources>
                    <Style TargetType="{x:Type OrderEntry:SalesOrderLineItemCreate}">
                        <Style.Triggers>
                            <DataTrigger 
                                    Binding="{Binding RelativeSource=
                                      {
                                         RelativeSource 
                                         Mode=FindAncestor, 
                                         AncestorType={x:Type ListBoxItem}
                                      }, 
                                      Path=IsSelected
                                     }" Value="True">
                                <Setter Property="Background" Value="LightBlue" />
                                <Setter Property="Foreground" Value="Black" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </OrderEntry:SalesOrderLineItemCreate.Resources>
            </OrderEntry:SalesOrderLineItemCreate>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

<TextBlock Grid.Row="2" 
           Text="Credit Memo" 
           HorizontalAlignment="Center"
           VerticalAlignment="Center"
           FontSize="48" Height="Auto"
           FontStyle="Italic"
           Foreground="Red"
           Opacity=".25">
    <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=OrderType}" Value="CR">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=OrderType}" Value="CU">
                    <Setter Property="Visibility" Value="Hidden" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

1 个答案:

答案 0 :(得分:126)

<TextBlock IsHitTestVisible="False" .../>