从另一个应用程序启动时,Xaml的ListBox中的滚动条的行为会有所不同

时间:2019-01-08 12:15:13

标签: c# wpf xaml

我正在处理Xaml表单,其中包含一个ListBox。从示例调用应用程序(使用C#在Windows Forms中开发)启动时,滚动条显示为垂直。从另一个第三方应用程序(我相信是WPF应用程序)启动时,该表单会水平显示滚动条。我的ListBox的Xaml代码是

<ListBox x:Name="AppliedTagsListBox" ItemsSource="{Binding Path=Tags, Mode=TwoWay}" Style="{StaticResource TagsListBoxStyle}" ItemContainerStyle="{StaticResource TagsListBoxItemStyle}" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" BorderBrush="Transparent"/>

<Style x:Key="TagsListBoxStyle" TargetType="{x:Type ListBox}">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel IsItemsHost="True"></WrapPanel>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border BorderThickness="1" BorderBrush="LightGray" CornerRadius="15,15,15,15" Margin="0,0,5,3">
                        <Border.Style>
                            <Style>
                                <Style.Triggers>
                                    <Trigger Property="Border.IsMouseOver" Value="True">
                                        <Setter Property="Border.Background" Value="SkyBlue"/>
                                    </Trigger>

                                </Style.Triggers>
                            </Style>
                        </Border.Style>
                        <DockPanel>
                            <TextBlock Padding="15,6,7,7" Text="{Binding}"/>
                            <Button FontWeight="Bold" Content="X" Background="Transparent" Margin="5,0,12,0" TextBlock.TextAlignment="Center" HorizontalAlignment="Stretch" BorderBrush="Transparent" Command="{Binding Path=RemoveTag}">
                                <Button.Resources>
                                    <Style TargetType="{x:Type Button}">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type Button}">
                                                    <Border Background="Transparent">
                                                        <!--<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center"/>-->

                                                        <Image Height="10" Width="10" Source="images/icons/Cross.32.png"/>
                                                    </Border>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Cursor" Value="Hand"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </Button.Resources>
                            </Button>
                        </DockPanel>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>


 <Style x:Key="TagsListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border Background="Transparent">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

关于如何在两个应用程序上获得相同行为的任何建议。

0 个答案:

没有答案