C
C#15mo ago
MotherBroker

❔ ui page : button offset

hello guys i have a frame displaying a page where i have a button, however there's an offset when i run the app here is my xaml button : <Button x:Name="testbutton" Content="Button" HorizontalAlignment="Left" Margin="40,247,0,0" VerticalAlignment="Top" Style="{DynamicResource ButtonStyle1}" Background="#FF24262F" Foreground="#FFBFBFBF" FontWeight="Bold" Width="55"/> i'm still pretty new to xaml and i have no clue what could be the issue. Thanks for your help in advance
5 Replies
MotherBroker
MotherBrokerOP15mo ago
Buddy
Buddy15mo ago
$rulesofwpf
MODiX
MODiX15mo 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
Buddy
Buddy15mo ago
Your issue lies here:
❌ Avoid the WPF Designer to eliminate a category of confusing bugs.
❌ Don't rely on Margin as the primary tool for layouts.
❌ Avoid the WPF Designer to eliminate a category of confusing bugs.
❌ Don't rely on Margin as the primary tool for layouts.
As Margin is the spacing between elements, it messes up layout when resized or when layout changes. You must use the layout controls, such as Grid, StackPanel, DockPanel, etc. Instead of the designer, write XAML by hand and rely on the hot reload. Just debug your app, make changes in the XAML, save it (CTRL + S) then the changes will be visible in the running app directly.
Accord
Accord15mo 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