Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • B.O.B.
    Participant
    Post count: 5

    I wrote some cell template resources to be applied to specific columns. One of which was to take a value that was coming in as an enum and passing it to a value converter to format it into a nice string format. The same should work for you.

    Here’s the template:

            <DataTemplate x:Key="EnumCellTemplate">
                <Grid>
                    <TextBlock x:Name="txt"
                               VerticalAlignment="Center"
                               TextTrimming="CharacterEllipsis">
                        <TextBlock.Style>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Text"
                                        Value="{Binding Converter={StaticResource EnumStr}}" />
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </Grid>
            </DataTemplate>

    Then in the Columns definition of the DataGridControl, you just have to define the column and set the CellContentTemplate. Something like:

    <g:DataGridControl.Columns>
       <g:Column CellContentTemplate="{StaticResource EnumCellTemplate}" FieldName="MyEnumField" />

    You can use the above to do all kinds of things – not just change d to surprise. For instance, I have another cell template that takes the value and uses that to return an ImageBrush that gets applied to a Canvas so I can display an image based on the value.

    B.O.B.
    Participant
    Post count: 5

    I made a little progress on this one. I added a readonly property called HasChildRows to master item class that returns true if the count of the child binding list > 0.

    I then was able to use FindAncestor and bind to the parent DataRow.DataContext.HasChildRows. This works, technically.

                                      Visibility="{Binding Mode=OneWay,
                                                           RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                          AncestorType={x:Type g:DataRow}},
                                                           Path=DataContext.HasChildRows,
                                                           Converter={StaticResource BooleanToVisibilityConverter}}"

    ^ the problem with the above is at runtime, Visual Studio has a silent binding error for every new row that gets loaded:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=’Xceed.Wpf.DataGrid.DataRow’, AncestorLevel=’1”. BindingExpression:Path=DataContext.HasChildRows;

    ^ So it looks like binding is failing (at least at first) then succeeding. Is there a better way to bind so it isn’t failing at first. I’m just worried about performance if there is a bunch of rows from the master table are returned in query and every single row is going to initially fail it’s binding.

    B.O.B.
    Participant
    Post count: 5

    XAML code with the less than/greater than chars replaced with html codes:

                        <g:TableView.ExpandGroupGlyph>
                            <DataTemplate>
                                <!--  Not sure why the wonkiness, but getting the icon centered required a weird margin + wrapper grid.  -->
                                <Grid x:Name="grd"
                                      Width="24"
                                      VerticalAlignment="Stretch"
                                      Background="Transparent">
                                    <Grid.Effect>
                                        <DropShadowEffect BlurRadius="0"
                                                          RenderingBias="Performance"
                                                          ShadowDepth="1" />
                                    </Grid.Effect>
                                    <Border x:Name="brd"
                                            Width="16"
                                            Height="16"
                                            Margin="3,12"
                                            VerticalAlignment="Center"
                                            BorderBrush="LightGray"
                                            BorderThickness="1">
                                        <Border.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding ElementName=grd,
                                                                                   Path=IsMouseOver}"
                                                                 Value="True">
                                                        <Setter Property="Border.Background"
                                                                Value="{DynamicResource appIconColor}" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Border.Style>
                                        <Path Width="10"
                                              Height="10"
                                              Margin="1"
                                              Data="M0,5 H10 M5,5 V10Z"
                                              Stroke="White"
                                              StrokeThickness="2" />
                                    </Border>
                                </Grid>
                            </DataTemplate>
                        </g:TableView.ExpandGroupGlyph>
Viewing 3 posts - 1 through 3 (of 3 total)