Binding Rows/Columns in ItemsPanelTemplate not allowed

5 posts, 1 answers
  1. Ricardo
    Ricardo avatar
    44 posts
    Member since:
    May 2018

    Posted 20 Aug 2018 Link to this post

    Hi,

     

    I'm following the example of RestoredTilesToSpanMultipleRowsAndColumns_WPF.

     

    I want to define dynamic rows/columns. I tried the following:

    <Style x:Key="tileViewPanel" TargetType="telerik:RadTileView">
        <Style.Resources>
            <System:Object x:Key="RowsCount"/>
            <System:Object x:Key="ColumnsCount"/>
        </Style.Resources>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <local:Multicolumns RowsCount="{DynamicResource RowsCount}" ColumnsCount="{DynamicResource ColumnsCount}"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

     

    Error:

    System.Windows.Markup.XamlParseException: 'A 'DynamicResourceExtension' cannot be set on the 'RowsCount' property of type 'TemplateForm'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject.'

     

    I also tried:

     

    <Style x:Key="tileViewPanel" TargetType="telerik:RadTileView">
                <Style.Resources>
                    <System:Object x:Key="RowsCount"/>
                    <System:Object x:Key="ColumnsCount"/>
                </Style.Resources>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <local:Multicolumns RowsCount="{Binding RowsCount}" ColumnsCount="{Binding ColumnsCount}"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

    Error:

    System.Windows.Markup.XamlParseException: 'A 'Binding' cannot be set on the 'RowsCount' property of type 'TemplateForm'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.'

    Does anyone knows how i can define dynamic rows/columns for this example?

     

    Regards

     

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 23 Aug 2018 Link to this post

    Hello Ricardo,

    Thank you for the provided code snippets. 

    Indeed it is not possible to set a DynamicResourceExtension or a Binding on the RowsCount and ColumnsCount properties since they are normal clr properties. In order to achieve what you are going for, you can change those properties to be DependencyProperties. Can you take a look at the Dependency properties overview and the Custom Dependency Properties articles in the MSDN documentation? 

    I hope this helps.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Ricardo
    Ricardo avatar
    44 posts
    Member since:
    May 2018

    Posted 23 Aug 2018 in reply to Vladimir Stoyanov Link to this post

    i tried the following:

     

    Xaml:

    <Style x:Key="tileViewPanel" TargetType="telerik:RadTileView">
                <Style.Resources>
                    <System:Object x:Key="RowsCount"/>
                    <System:Object x:Key="ColumnsCount"/>
                </Style.Resources>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <local:Multicolumns RowsCount="{DynamicResource RowsCount}" ColumnsCount="{DynamicResource ColumnsCount}"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

     

    Default rows/columns (Window_Loaded event): -> OK

    Style style = FindResource("tileViewPanel") as Style;
               style.Resources["RowsCount"] = 16;
               style.Resources["ColumnsCount"] = 3;
     
               Form.Style = style;

     

    Button Event: -> Not Ok

    Style style = FindResource("tileViewPanel") as Style;
                style.Resources["RowsCount"] = 17;
                style.Resources["ColumnsCount"] = 4;

     

    When i click on the button i get the following error:

    System.InvalidOperationException: 'ResourceDictionary is read-only and cannot be modified.'

    i have no idea what is wrong, he seems to be working in the window_loaded event.

     

  4. Answer
    Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 28 Aug 2018 Link to this post

    Hello Ricardo,

    Thank you for the provided samples.

    While I cannot be sure what the reason for the described exception is without being able to reproduce it on my side, it seems that you have discussed a similar scenario in the following thread: Set Row and column span from code behind. Can you confirm that the suggested approach in that thread of defining the panel dynamically suits your requirements?

    Additionally, may I ask you to continue the discussion in the other thread in order to avoid duplication? Thank you in advance for your understanding.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Ricardo
    Ricardo avatar
    44 posts
    Member since:
    May 2018

    Posted 28 Aug 2018 Link to this post

    The solution provided in the other scenario works :).

     

    thanks for the help

Back to Top