我称自己为ComboBox
,其中包含正常的Popup
。现在我想在Popup
中向用户显示一条消息,如果集合为空(Count = 0),而不是绑定属性为Null
时。该邮件应该只是一些TextBlock
,其中包含一些文字
我试图用Trigger
来改变它,但是没有用。 Popup
看起来像这样:
<Popup Name="PART_Popup" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Grid.ColumnSpan="2" Placement="Bottom">
<Border x:Name="DropDownBorder" Height="Auto" MaxHeight="100" Width="100" BorderBrush="Blue" BorderThickness="1">
<ScrollViewer x:Name="DropDownScrollViewer" Background="White">
<ContentControl x:Name="PopupContent">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" />
</Grid>
</ContentControl>
</ScrollViewer>
</Border></Popup>
答案 0 :(得分:1)
您可以使用HasItems
的{{1}}属性。在此,我在ComboBox
内加TextBlock
,并根据Popup
控制Visibility
。
HasItems
转换器,
<Popup
x:Name="PART_Popup"
Grid.ColumnSpan="2"
Margin="1"
AllowsTransparency="true"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Bottom"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<Popup.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<local:InverseBooleanToVisiblityConverter x:Key="InverseBooleanToVisiblityConverter" />
</Popup.Resources>
<Grid>
<TextBlock Text="No Items" Visibility="{Binding HasItems, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBooleanToVisiblityConverter}}" />
<Border
x:Name="dropDownBorder"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1"
Visibility="{Binding HasItems, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
<ScrollViewer x:Name="DropDownScrollViewer">
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
<Canvas
x:Name="canvas"
Width="0"
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Rectangle
x:Name="opaqueRect"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Fill="{Binding Background, ElementName=dropDownBorder}" />
</Canvas>
<ItemsPresenter
x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ScrollViewer>
</Border>
</Grid>
</Popup>
答案 1 :(得分:0)
使用组合框的itemsource并初始化您的集合。如果您的集合中不包含任何项目,请使弹出窗口可见,等等......
collection.count