spiegelp / MaterialDesignExtensions

Material Design Extensions is based on Material Design in XAML Toolkit to provide additional controls and features for WPF apps
https://spiegelp.github.io/MaterialDesignExtensions/
MIT License
754 stars 122 forks source link

Programmatically set the icon of a button in MaterialWindow TitleTemplate #133

Open melcug opened 3 years ago

melcug commented 3 years ago

I've tried without success to set the icon of a button in MaterialWindow TitleTemplate using the following code:

var iconFieldUser = (this.TitleTemplate.LoadContent() as Grid).FindName("iconFieldUser") as PackIcon;
iconFieldUser.Kind = PackIconKind.LocalAreaNetworkConnect;
iconFieldUser.Foreground = Brushes.LightSeaGreen;
iconFieldUser.InvalidateVisual();

Running the above code not changing anything.

More, when I use TitleTemplate in MaterialWindow I get errors like the one below:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='MaterialDesignExtensions.Controls.MaterialWindow', AncestorLevel='1''. BindingExpression:Path=BorderForegroundBrush; DataItem=null; target element is 'Button' (Name='fieldUser'); target property is 'Foreground' (type 'Brush')