lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.29k stars 702 forks source link

Styling for ListView causes GridViewColumn DisplayMemberBinding not to work. #198

Open GiuseppeIII opened 2 years ago

GiuseppeIII commented 2 years ago

Styling for ListView causes GridViewColumn DisplayMemberBinding not to work.

blakepell commented 2 years ago

I'm seeing the same thing. I added this to test the theory and then my GridView columns displayed (obviously with the stylings missing).

  <ListView.Style>
      <Style TargetType="{x:Type ListView}"/>
  </ListView.Style>
Zaitonn commented 1 year ago

https://github.com/lepoco/wpfui/blob/6212d2646c52a01624cc14ebfe1e209b073d99c2/src/Wpf.Ui/Styles/Controls/ListView.xaml#L45

Just try to change that line to this

<GridViewRowPresenter/>

and it seems to work (It's just that there aren't dividers of column) image

<ListView Name="MemberListView"
    ContextMenuOpening="MemberListView_ContextMenuOpening"
    SelectionMode="Single">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="ID"
                DisplayMemberBinding="{Binding ID}" />
            <GridViewColumn Header="群角色"
                DisplayMemberBinding="{Binding Role}" />
            <GridViewColumn Header="昵称"
                DisplayMemberBinding="{Binding Nickname}" />
            <GridViewColumn Header="群名片"
                DisplayMemberBinding="{Binding Card}" />
            <GridViewColumn Header="游戏ID"
                DisplayMemberBinding="{Binding GameID}" />
        </GridView>
    </ListView.View>
</ListView>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ui:ControlsDictionary />
        <ui:ThemesDictionary Theme="Light" />
    </ResourceDictionary.MergedDictionaries>
    <Style TargetType="ListViewItem">
        <Setter Property="Foreground">
            <Setter.Value>
                <SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Background"
            Value="Transparent" />
        <Setter Property="BorderBrush">
            <Setter.Value>
                <SolidColorBrush Color="{DynamicResource SystemAccentColorSecondary}" />
            </Setter.Value>
        </Setter>
        <Setter Property="SnapsToDevicePixels"
            Value="True" />
        <!--<Setter Property="OverridesDefaultStyle" Value="True" />-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border x:Name="Border"
                        Margin="0"
                        Padding="4"
                        Background="{TemplateBinding Background}"
                        BorderThickness="1"
                        CornerRadius="4">
                        <Border.BorderBrush>
                            <SolidColorBrush Opacity="0.0"
                                Color="{DynamicResource SystemAccentColorSecondary}" />
                        </Border.BorderBrush>
                        <GridViewRowPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected"
                            Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Border"
                                            Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Opacity)"
                                            From="0.0"
                                            To="1.0"
                                            Duration="0:0:.16" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Border"
                                            Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Opacity)"
                                            From="1.0"
                                            To="0.0"
                                            Duration="0:0:.16" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
blakepell commented 1 year ago

@Zaitonn Thank you for sharing. Your approach works for me in the short term. Again, thank you, it's much appreciated.