C
C#14mo ago
Elio

❔ WPF Border Button

Hello, have you any idea why there is this gray border on the button ?
the dimensions of my image is 40x30 so it should fit in my button without this gray border
6 Replies
canton7
canton714mo ago
I think that's probably part of the button -- your image is being placed inside the button, but doesn't replace the styling it already has You can replace the ControlTemplate instead -- that should replace everything, including the press styling, etxc
<Button ...>
<Button.Template>
<ControlTemplate>
<Image .../>
</ControlTemplate>
</Button.Template>
</Button>
<Button ...>
<Button.Template>
<ControlTemplate>
<Image .../>
</ControlTemplate>
</Button.Template>
</Button>
Elio
Elio14mo ago
perfect that was the problem it works well, i will create a style rn to reduce the xaml code in my page thanks you !
Buddy
Buddy14mo ago
One more thing, do not use the designer If Margins are larger than 30, it's bad. $rulesofwpf
MODiX
MODiX14mo ago
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Elio
Elio14mo ago
Yeah I know about margin just for the beginning I'm using this to have a preview I will set all my stuff in the page without it after I've validated my style I'm still tryin to figure out how xaml work really for many things 😅
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts