This is a migrated thread and some comments may be shown as answers.

[Solved] Failed to get AlternateRowStyleSelector working.

2 Answers 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
leo
Top achievements
Rank 1
leo asked on 06 Aug 2011, 10:11 AM
Hi,

I have problem to get AlternateRowStyleSelector working as expected.

Here is xaml:
<UserControl .....>

    <UserControl.Resources>
        <ContentControl x:Key="vm" Content="{Binding}"/>
        <converters:MissingIconVisibilityConverter x:Key="MissingIconVisibilityConverter" />
        <converters:MissingStyleSelector x:Key="MissingStyleSelector" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">

        <telerik:RadGridView ItemsSource="{Binding Path=MyObjectList}" AlternateRowStyleSelector="{StaticResource MissingStyleSelector}"
CanUserFreezeColumns="False" AutoGenerateColumns="False" AutoExpandGroups="True" CanUserDeleteRows="False"
CanUserInsertRows="False" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False"  CanUserSortColumns="False">

            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Width="26" IsResizable="False" IsReadOnly="True">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="18" Height="18" Visibility="{Binding Path=IsMissing, Converter={StaticResource MissingIconVisibilityConverter}}" Source="/Commons.Styles;component/Images/Alter.png"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="DAY/HR" IsReadOnly="True" DataMemberBinding="{Binding Path=ForecastedDate, Converter={StaticResource DayHourConverter}}" Width="*" Background="{Binding Path=IsMissing}" />
                <telerik:GridViewDataColumn Header="Action" Width="42" IsResizable="False" IsReadOnly="True">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Button prism:Click.Command="{Binding Source={StaticResource vm}, Path=Content.RemoveCommand}" prism:Click.CommandParameter="{Binding Path=GUID}" Template="{StaticResource RemoveXButtonTemplate}" Cursor="Hand" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>

        </telerik:RadGridView>

    </Grid>

</UserControl>


Then below is code:
public class MissingStyleSelector : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            var style = new Style(typeof(GridViewRow));
            var row = (GridViewRow)container;
            var obj = (MyObject)item;

            if (obj.IsMissing == true)
            {
                style.Setters.Add(new Setter(GridViewRow.BackgroundProperty, new SolidColorBrush(Colors.Red)));
            }
            else
            {
                style.Setters.Add(new Setter(GridViewRow.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
            }

            return style;
        }
    }

I can build and run my solution, but the expected stuff is not working. please kindly advise.

2 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 08 Aug 2011, 10:28 AM
Hi Leo,

Would you please shed some more light on this issue. I have prepared an example project with 2011.2.801 (latest) binaries and it is working fine. I am attaching it for your reference.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
leo
Top achievements
Rank 1
answered on 10 Aug 2011, 07:43 PM
Hi,

Really appreciate your feedback and sample solutions. it's working in my local.
I was just too busy to reply.

After struggling for a while, I found I'm missing "AlternationCount="1"" in gridview of xaml, it's functioning as my expected after I added. Cheer!!!


Tags
GridView
Asked by
leo
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
leo
Top achievements
Rank 1
Share this question
or