New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting TextBox FontFamily property from Style causes XamlObjectWriterException #2194
Comments
Solution is ridiculously simple. In file \src\Markup\Avalonia.Markup.Xaml\Converters\FontFamilyTypeConverter.cs replace |
@ksigne The real issue here is the non present context. Your "solution" would just hide it in my opinion. This issue is not about FontFamily. Uris in general fail to work with avares scheme inside a style. This needs to be fixed. |
I don't see a big trouble with non present context. I've checked it and |
Without a present context relative uris would never work. That would still produce an exception when you expect it to work. Uris defined in styles should work in the same way as uris defined directly on controls. |
Well, I was able to pull baseuri into setter converter.
from
The rest is TypeDescriptorImpersonator. You cannot access actual Service Resolver as it is internal. But the only service is actually located is through this method:
so you implement Other way is to add public property on |
Do temp workarounds exist for this issue? |
I guess you could define the font family in code by defining a static property and reference it in your style. |
Any plans to fix this in the near future 😅 ? |
@kekekeks will this be fixed by the XAML compiler? |
I've added <StackPanel.Styles>
<Style Selector="TextBox">
<Setter Property="FontFamily" Value="Consolas"/>
</Style>
</StackPanel.Styles> To Styles styles = ((StyledElement)stackPanel5).Styles;
Style style;
Style item = style = new Style();
_AvaloniaXamlIlContext.ParentsStack.Add(style);
Style style2 = style;
style2.Selector = ((Selector)null).OfType(typeof(TextBox));
IList<ISetter> setters = style2.Setters;
Setter setter;
Setter item2 = setter = new Setter();
_AvaloniaXamlIlContext.ParentsStack.Add(setter);
Setter setter2 = setter;
setter2.Property = TemplatedControl.FontFamilyProperty;
setter2.Value = (object)(FontFamily)new FontFamilyTypeConverter()
.ConvertFrom(_AvaloniaXamlIlContext, CultureInfo.InvariantCulture, "Consolas");
_AvaloniaXamlIlContext.ParentsStack.RemoveAt(_AvaloniaXamlIlContext.ParentsStack.Count - 1);
setters.Add(item2);
_AvaloniaXamlIlContext.ParentsStack.RemoveAt(_AvaloniaXamlIlContext.ParentsStack.Count - 1);
styles.Add(item); which seems to work. |
@jmacato XAML compiler will be probably merged after 0.8 release. |
@kekekeks Does that mean AvaloniaXamlLoader will be gone after 0.8? |
@kekekeks sorry i misclicked the close issue button, i was trying to reply if we could modify/fix the TypeConverter for FontFamily to avoid ParentStack |
The issue is not the converter the issue is within Portable.Xaml |
@x2bool |
Can you give an example how to do it? |
Compiler is now merged, so it should work. |
Hello! I have similar problem, but with Button control, and now, at Avalonia 0.8.1, FontFamily from style causes XamlObjectWriterException |
I've tried it on Avalonia 0.8.999-cibuild0003136-beta. Problem exist |
I also see the same issue as MiKaMaru with the Button control. I'm able to set the other properties using the syntax below, but I get the error: "NullReferenceException: Object reference not set to an instance of an object." for the FontFamily line.
|
version: 0.7.1-build989-beta
The text was updated successfully, but these errors were encountered: