LIstview项绑定但不可见WPF [英] LIstview items bound but not visible WPF

查看:71
本文介绍了LIstview项绑定但不可见WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView的ItemsSource显示已加载的项目,但项目在屏幕上不可见.

ItemsSource of ListView shows loaded item but items are not visible in the screen.

<UserControl x:Class="...Controls.ControlToolbar"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:TuningInterfaceModel.Controls"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>

    <local:StringFormatToImageSourceConverter x:Key="StringToImage" />
</UserControl.Resources>
<Grid>
    <ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" x:Name="tStack">

        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel  VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Image Source="{Binding Path=Key, Converter={StaticResource StringToImage}
 , ConverterParameter=../Images/ControlIcons/{0}.ico}" />
                    <TextBlock Text="{Binding Key}" FontSize="10px"  Width="60px" Margin="2,0,0,0"  />
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListViewItem}">
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True" >
                                    <Setter Property="Cursor" Value="/Images/Cursor/grab.cur"/>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsMouseOver" Value="True" />
                                        <Condition Property="local:MouseExtensions.IsMouseLeftButtonDown" Value="True" />
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Cursor" Value="/Images/Cursor/Handover.cur" />
                                </MultiTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>
</Grid>
</UserControl>

推荐答案

您的< Style TargetType ="{x:Type ListViewItem}"> 有错.它将 Template 设置为 ControlTemplate ,它仅包含没有任何内容的触发器.

Your <Style TargetType="{x:Type ListViewItem}"> is at fault. It is setting Template as a ControlTemplate that only contains triggers without any content.

如果我的水晶球没有让我失望,您可能想要删除控件模板,而改用 Style.Triggers .

If my crystal balls don't fail me, you may want to remove the control template and use Style.Triggers instead.

<Style TargetType="{x:Type ListViewItem}">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True" >
            <Setter Property="Cursor" Value="/Images/Cursor/grab.cur"/>
        </Trigger>
    </Style.Triggers>
    <!-- More triggers -->
</Style>

这篇关于LIstview项绑定但不可见WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆