Comments (3)
As workaround, try add this code before use triggers somewhere in applications initialization:
if (!TypeDescriptor.GetAttributes(typeof(Avalonia.Thickness)).Cast<Attribute>().Any(x => x is TypeConverterAttribute))
{
TypeDescriptor.AddAttributes(typeof(Avalonia.Thickness), new TypeConverterAttribute(typeof(ThicknessTypeConverter)));
}
/*...*/
public class ThicknessTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(string) || sourceType == typeof(double) || sourceType == typeof(int);
}
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
return value switch
{
string stringValue => new Avalonia.Thickness(double.Parse(stringValue, culture)),
double doubleValue => new Avalonia.Thickness(doubleValue),
int intValue => new Avalonia.Thickness(intValue),
_ => base.ConvertFrom(context, culture, value)
};
}
}
ChangePropertyAction
internally uses a heuristic way of converting types (e.g. string
->Avalonia.Thickness
and string
->Avalonia.Brush
in your case) and it falldown to call TypeDescriptor.GetConverter
. Using reflection it tries to find custom TypeConverter
for destynation type. There is no default converter today, but you can do it yourself.
from avalonia.xaml.behaviors.
Same problem but with padding:
<i:Interaction.Behaviors>
<ia:DataTriggerBehavior Binding="{Binding IsExpanded}" ComparisonCondition="Equal" Value="true">
<ia:ChangePropertyAction TargetObject="{Binding #btn}" PropertyName="Content" Value=""/>
<ia:ChangePropertyAction TargetObject="{Binding #btn}" PropertyName="Padding" Value="5,7,5,3"/>
</ia:DataTriggerBehavior>
<ia:DataTriggerBehavior Binding="{Binding IsExpanded}" ComparisonCondition="Equal" Value="false">
<ia:ChangePropertyAction TargetObject="{Binding #btn}" PropertyName="Padding" Value="9,4,1,6"/>
<ia:ChangePropertyAction TargetObject="{Binding #btn}" PropertyName="Content" Value=""/>
</ia:DataTriggerBehavior>
</i:Interaction.Behaviors>
When trying to implement the suggested workaround I can cannot find class Avalonia.Padding
. Seems like it would be a pretty low leve object and included in the Avalonia library(?):
public class PaddingTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(string) || sourceType == typeof(double) || sourceType == typeof(int);
}
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
return value switch
{
string stringValue => new Avalonia.Padding(double.Parse(stringValue, culture)), // error: .Padding(...) not found
};
}
}
from avalonia.xaml.behaviors.
Instead, it should be parsed compile time. But for that some attributes-hints should be created.
from avalonia.xaml.behaviors.
Related Issues (20)
- Native Aot for Avalonia.Xaml.Behaviors HOT 2
- ListBox control firing SelectionChanged event before updating SelectedItem property HOT 4
- Binding to attached property exception HOT 1
- [D&D] Unable using scrollbar if scrollview is inside ListBoxItem
- Textbox focus HOT 2
- Setting Behaviors via Styles is not additive HOT 2
- Microsoft.NETFramework.ReferenceAssemblies included as dependency HOT 1
- Support KeyModifiers in more Triggers and related issues
- DataTriggerBehavior does not work correctly in ContextMenu
- Using EventTriggerBehavior to bind the closed command doesn't work HOT 4
- EventTriggerBehavior is invalid in Unloaded event HOT 5
- doc site http://wieslawsoltes.github.io/AvaloniaBehaviors/ 404 this moment.
- Update package to 11.0.4 please HOT 3
- Dragging ListBoxItem on Android
- 11.0.9.1 and 11.0.9.2 Breaks Avalonia HOT 1
- DataTriggerBehavior doesn't work with DataGridRow style HOT 1
- ButtonClickEventTriggerBehavior misses previously pressed modifiers
- CS0433 caused by TrimmingAttributes.cs HOT 5
- Broken wiki link HOT 1
- TabControl TabItems can only be moved once HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avalonia.xaml.behaviors.