Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Style-Property to Bound-Column #93

Open
VisualAlf opened this issue Jan 23, 2025 · 0 comments
Open

Add a Style-Property to Bound-Column #93

VisualAlf opened this issue Jan 23, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@VisualAlf
Copy link

Having a Style for a column would give the user a way to influence the appearance of the cells within a column.

Example:

Image

In this example, the ID-Field is rightjustified, Field2/3 are centered, and Field1 is ...special.

How I did it

1- created a new DP ColumnStyle (of type Style) within TableViewBoundColumn.

2- modified TableViewTextColumn.GenerateElement(...) (and same way also Date- and NumberColumn)

        var textBlock = new TextBlock();
        textBlock.SetBinding(TextBlock.TextProperty, Binding);

        if (ColumnStyle != null && ColumnStyle.TargetType == typeof(TextBlock))
            textBlock.Style = ColumnStyle;

        textBlock.Margin = new Thickness(12, 0, 12, 0); // make sure the ColumnStyle doesn't change the Margin

        return textBlock;

3- The xaml looks like so:

        <tab:TableView x:Name="MyTV"
                       Height="450"
                       RowHeight="60"
                       RowMaxHeight="80"
                       Style="{StaticResource LookupTable}" 
                       SelectionMode="Single"
                       ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                       >
            <tab:TableView.Resources>
                <Style x:Name="centerTextStyle" TargetType="TextBlock">
                    <Setter Property="HorizontalTextAlignment" Value="Center" />
                    <Setter Property="Foreground" Value="Red" />
                </Style>

                <Style x:Name="centerBoldTextStyle" TargetType="TextBlock">
                    <Setter Property="HorizontalTextAlignment" Value="Center" />
                    <Setter Property="FontWeight" Value="Bold" />
                </Style>

                <Style x:Name="rightTextStyle" TargetType="TextBlock">
                    <Setter Property="HorizontalTextAlignment" Value="Right" />
                </Style>

                <Style x:Name="moreTextStyle" TargetType="TextBlock">
                    <Setter Property="HorizontalTextAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="Foreground" Value="LightCyan" />
                    <Setter Property="FontFamily" Value="Century Gothic" />
                    <Setter Property="FontSize" Value="11" />
                    <Setter Property="FontStyle" Value="Italic" />
                    <Setter Property="Padding" Value="5 10" />
                    <Setter Property="MaxHeight" Value="58" />
                    <Setter Property="TextWrapping" Value="WrapWholeWords" />
                    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
                </Style>
            </tab:TableView.Resources>

            <tab:TableView.Columns>
                <tab:TableViewNumberColumn Header="ID" Width="30" Binding="{Binding ItemId}" 
                                           ColumnStyle="{StaticResource rightTextStyle}" />

                <tab:TableViewTextColumn Header="Field 1" Width="180" Binding="{Binding ItemName}" 
                                         ColumnStyle="{StaticResource moreTextStyle}" />

                <tab:TableViewTextColumn Header="Field 2" Width="100" Binding="{Binding ItemIntValue}" 
                                         ColumnStyle="{StaticResource centerTextStyle}"/>
                
                <tab:TableViewDateColumn Header="Field 3" Width="100" Binding="{Binding ItemDate}" 
                                         ColumnStyle="{StaticResource centerBoldTextStyle}"/>

            </tab:TableView.Columns>
        </tab:TableView>

Other Ideas

we could have the numberColumn right-aligned by default, the user could overwrite that with the style.

@VisualAlf VisualAlf added the enhancement New feature or request label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant