Closed ImaginaryDevelopment closed 8 years ago
could you paste some code - would help me understand the issue.
let createFAButton ()=
let b = Button()
let t = TextBlock()
let binding = new Binding()
// binding.Path <- PropertyPath( "FontAwesomeIcon")
// binding.Source <- ???
binding.Source <- "Flag"
binding.Converter <- CssClassNameConverter(Mode=CssClassConverterMode.FromStringToIcon)
BindingOperations.SetBinding(t, TextBox.TextProperty, binding) |> ignore
b.Content <- t
// b.Content <- FontAwesome.WPF.ImageAwesome.CreateImageSource( FontAwesome.WPF.FontAwesomeIcon.FastBackward, Media.Brushes.Black)
// let fa = FontAwesome.WPF.FontAwesome()
// b.Content <- fa
// b.FontFamily <- "pack://application:,,,/FontAwesome.WPF;component/#FontAwesome"
b
lots of sample other attempts in comments
translation:
Button CreateFAButton()
{
var b = new Button();
var t = new TextBlock();
var binding = new Binding();
binding.Source = "Flag";
binding.Converter = new CssClassNameConverter { Mode = CssClassConverterMode.FromStringToIcon);
BindingOperations.SetBinding(t, TextBox.TextProperty, binding);
b.Content = t;
return b;
}
also tried
let createFAButton ()=
let b = Button()
FontAwesome.WPF.Awesome.SetContent(b, FontAwesome.WPF.FontAwesomeIcon.FastBackward)
b
translated to C#:
Button CreateFAButton()
{
var b = new Button();
FontAwesome.WPF.Awesome.SetContent(b, FontAwesome.WPF.FontAwesomeIcon.FastBackward);
return b;
}
not tested but you should be able to do this:
let t = FontAwesome()
for more see: https://github.com/charri/Font-Awesome-WPF/blob/master/src/FontAwesome.WPF/FontAwesome.cs
tried making what I think your recommended adjustment was, did not work
let createFAButton ()=
let b = Button()
let t = FontAwesome.WPF.FontAwesome()
let binding = Binding()
binding.Source <- "Flag"
binding.Converter <- CssClassNameConverter()
BindingOperations.SetBinding(t, TextBox.TextProperty, binding) |> ignore
b.Content <- t
b
Would you mind taking 5 min to look at the FontAwesome.cs code?
you could just assign the actual icon instead of the binding, as your not binding to anything that would cause a INotifyPropertyChanged event:
t.Icon = FontAwesomeIcon.Flag;
If you need to use bindings then you need to use the FontAwesome.IconProperty (TextProperty will not work)
cheers
that worked, I did look at the code you linked, twice. I have/had no idea how to interpret it. this code works, but I bet I don't need to be doing all that work. like I didn't actually need a binding.
working code:
let createFAButton ()=
let b = Button()
let t = FontAwesome.WPF.FontAwesome()
t.Icon <- FontAwesome.WPF.FontAwesomeIcon.Flag
let binding = Binding()
binding.Source <- "Flag"
binding.Converter <- CssClassNameConverter()
BindingOperations.SetBinding(t, TextBox.TextProperty, binding) |> ignore
b.Content <- t
b
how would I do it without using a binding?
nevermind, didn't need the binding stuff at all
let createFAButton ()=
let b = Button()
let t = FontAwesome.WPF.FontAwesome()
t.Icon <- FontAwesome.WPF.FontAwesomeIcon.Flag
b.Content <- t
b
thanks for the help and prompt replies.
There's an example of setting an icon, but none of TextBlock purely in code-behind, how would I do that? so far in my attempts the binding error is
FontAwesomeIcon
property not found on 'object'.