Multibinding a style class in code #15711
-
I'm trying to create a data template in code for a TreeDataGrid, and I want to have my data cells have a style class added if the user has write access to a specific data cell. Essentially, I want to turn this XAML into code, and I'm not sure how (specifically the part concerning the style class). I've already got the converter working for other items. I just need to convert this portion into code <DataTemplate x:DataType="datapoint:DataPoint">
<Label Content="Sample Text">
<Label.Classes.Edit>
<MultiBinding Converter="{StaticResource WriteAccessConverter}">
<Binding Path=""/>
<Binding Path="$parent[TreeDataGrid].((vm:ParameterTabViewModel)DataContext).ActiveUser"/>
</MultiBinding>
</Label.Classes.Edit>
</Label>
</DataTemplate> This is the closest I've been able to get (adding the class without the conditional binding) var cellTemplate = new FuncDataTemplate<DataRow>((_, _) => {
var label = new Label { [!Label.ContentProperty] = new Binding(bindingString + ".Text") };
label.Classes.Add("Edit");
return new ContentControl() { Content = label };
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Remove the <Window.Styles>
<Style Selector="TextBlock.big">
<Setter Property="FontSize" Value="36" />
</Style>
</Window.Styles>
<TextBlock x:Name="text" Text="Testing MultiBinding">
<Classes.big>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsA" />
<Binding Path="IsB" />
</MultiBinding>
</Classes.big>
</TextBlock> You also can't use syntax the same way you do in the You could also write your own |
Beta Was this translation helpful? Give feedback.
-
My solution:
Example of use:
|
Beta Was this translation helpful? Give feedback.
I see, sorry about that. You need to work with
StyledElement.BindClass
which is an extension method in theAvalonia
namespace. Converting my example...