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

Binding Rows/Columns in ItemsPanelTemplate not allowed

4 Answers 64 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 20 Aug 2018, 06:50 PM

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

 

4 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 23 Aug 2018, 03:42 PM
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.
0
Ricardo
Top achievements
Rank 1
answered on 23 Aug 2018, 04:21 PM

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.

 

0
Accepted
Vladimir Stoyanov
Telerik team
answered on 28 Aug 2018, 08:53 AM
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.
0
Ricardo
Top achievements
Rank 1
answered on 28 Aug 2018, 12:41 PM

The solution provided in the other scenario works :).

 

thanks for the help

Tags
TileView
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Ricardo
Top achievements
Rank 1
Share this question
or