Doesn't work for Setters
Error is returned: 'Binding' is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types
Can you provide the code that causes the error?
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.
Ok
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}"/>
Hello, can you provide minimal example project that demonstrates this issue? (csproj, xaml, cs)
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.
Ok, thank you, I will analyze it
any news on this? having same issue