CalcBinding icon indicating copy to clipboard operation
CalcBinding copied to clipboard

Doesn't work for Setters

Open arteny opened this issue 10 years ago • 8 comments

Error is returned: 'Binding' is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types

arteny avatar Mar 31 '15 21:03 arteny

Can you provide the code that causes the error?

Alex141 avatar Apr 01 '15 07:04 Alex141

My description seems was not full. And unfortunately I already missed (rewrote) that code. I have other Setters with well working CalcBinding. Next time I'll try to be more carefully to describe the issue.

arteny avatar Apr 03 '15 22:04 arteny

Ok

Alex141 avatar Apr 04 '15 07:04 Alex141

I get an error: 'Binding' is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types. It happens when I use CalcBinding in sub style. If I set properties for DataGrid:

  • CellStyle="{StaticResource InvertedMetroDataGridCell}" is valid
  • Style="{StaticResource InvertedDataGrid}" is invalid
<Style x:Key="InvertedMetroDataGridCell" TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">
    <Setter Property="LayoutTransform">
        <Setter.Value>
            <TransformGroup>
                <RotateTransform Angle="-90" />
                <ScaleTransform ScaleX="1" ScaleY="-1" />
            </TransformGroup>
        </Setter.Value>
    </Setter>
    <Setter Property="Width" Value="{calc:Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path='Parent.ActualWidth/(Items.Count+1)'}"/>
</Style>
<Style x:Key="InvertedDataGrid" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource MetroDataGrid}">
    <!-- other setters -->
    <Setter Property="CellStyle" Value="{StaticResource InvertedMetroDataGridCell}"/>
</Style>

For some reason this is a workaround:

<Setter Property="Tag" Value="{calc:Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path='Parent.ActualWidth/(Items.Count+1)'}"/>
<Setter Property="Width" Value="{Binding Path=Tag, RelativeSource={RelativeSource Self}, TargetNullValue=0}"/>

danielklecha avatar Nov 12 '19 13:11 danielklecha

Hello, can you provide minimal example project that demonstrates this issue? (csproj, xaml, cs)

Alex141 avatar Nov 12 '19 21:11 Alex141

Hi @Alex141 I prepared sample app on github. As I said it occurs when style attached to style which I use contains calc binding. But maybe the root cause is different...

In project you have 2 datagrids. First uses InvertedMetroDataGrid style and this generates issue. Second uses substyles directly and don't generates issue. Project require CalcBinding and MahApps.

This workaround with Tag and Width properties is working but I don't added it to demo. When you use Tag and Width properties in substyle then error is gone.

Thanks for help!

Edit: I use Windows 10 1903, VS2019 and project is set to .NET Framework 4.8.

danielklecha avatar Nov 13 '19 07:11 danielklecha

Ok, thank you, I will analyze it

Alex141 avatar Nov 14 '19 21:11 Alex141

any news on this? having same issue

jpgarza93 avatar Jun 14 '22 17:06 jpgarza93