首页 新闻 会员 周边 捐助

WPF Trigger

0
悬赏园豆:50 [已解决问题] 解决于 2014-01-26 13:45

要求符合条件的时候显示textblock,不符合条件的时候显示Menu,不知道怎么填了,附上一半的代码

<ComboBox Style="{StaticResource CboCommomStyle}" ItemsSource="{Binding StatusItems}" SelectedIndex="1" Margin="10,0,0,0">
                        <ComboBox.Resources>
                            <Style TargetType="MenuItem">//这句应该也是错的,不知道要填什么类型
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=StateType}" Value="True">
                                        //这里本来是要显示Textblock,但是不知道要怎么写
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ComboBox.Resources>
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Menu Background="Transparent">
                                    <MenuItem Header="{Binding State}" Command="{Binding ClickedCommand}">
                                        <MenuItem.Icon>
                                            <Image Stretch="None" Source="{Binding Icon}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </Menu>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

没有同名的主页 没有同名 | 初学一级 | 园豆:28
提问于:2014-01-24 16:29
< >
分享
最佳答案
0

<ComboBox Style="{StaticResource CboCommomStyle}" ItemsSource="{Binding StatusItems}" SelectedIndex="1" Margin="10,0,0,0">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Name="containerGrid">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="10"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Image HorizontalAlignment="Left" Name="imgState" Stretch="None" Source="{Binding Icon}"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Name="txtbState" Grid.Column="1" Text="{Binding State}"/>
                                    <Button Grid.ColumnSpan="2" Name="cmdBtn" Content="{Binding State}" Command="{Binding ClickedCommand}"
                                            Background="Transparent" BorderBrush="Transparent" BorderThickness="0"/>
                                </Grid>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsStateType}" Value="True" >
                                        <Setter Property="Visibility" Value="Hidden" TargetName="cmdBtn"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=IsStateType}" Value="False">
                                        <Setter Property="Visibility" Value="Hidden" TargetName="imgState"/>
                                        <Setter Property="Visibility" Value="Hidden" TargetName="txtbState"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

没有同名 | 初学一级 |园豆:28 | 2014-01-26 13:44
其他回答(2)
0

MenuItem?Menu呢?

YoMe | 园豆:545 (小虾三级) | 2014-01-25 14:44

 有的呐,就在MenuItem上面呀……额,无语

支持(0) 反对(0) 没有同名 | 园豆:28 (初学一级) | 2014-01-25 18:09
0

可以在msdn上查看下属性ItemTemplateSelector或者ItemContainerStyleSelector的用法,可以实现你想要的效果

收获园豆:50
Desmond | 园豆:281 (菜鸟二级) | 2014-01-26 09:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册