C
C#2y ago
FaNim

❔ binding Command in user control button problem

The problem is that nothing is happening but when i'm making normal button in my main window with Command and CommandParameter everything is fine what have i done wrong? And there is no errors in compilation
15 Replies
Buddy
Buddy2y ago
$rulesofwpf
MODiX
MODiX2y 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
Buddy2y ago
Please explain more in detail what the issue is
FaNim
FaNimOP2y ago
just when iam clicking buttons nothing happens it doesnt trigger the UpdateViewCommand from MainWindow it is reference to Command in my custom button
Buddy
Buddy2y ago
Please post the code of that button $paste
MODiX
MODiX2y ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
FaNim
FaNimOP2y ago
the most important references i send in pics
FaNim
FaNimOP2y ago
BlazeBin - gtqvzzibjhfx
A tool for sharing your source code with the world!
Buddy
Buddy2y ago
That says nothing, I'd like the full code of the button, not the XAML.
FaNim
FaNimOP2y ago
I gave there full code for button with xaml in it
FaNim
FaNimOP2y ago
I gave it in pastebin But maybe i gave you wrong link Ah okay i need to give link every class
FaNim
FaNimOP2y ago
BlazeBin - ozbufzywpqjw
A tool for sharing your source code with the world!
FaNim
FaNimOP2y ago
I have no idea whats wrong with it that it cant trigger that command and for reference
<Button x:Name="Btn"
Width="80"
Height="20"
FontSize="12"
Grid.Column="1"
Margin="10,5,110,0"
Content="TEST"
Command="{Binding UpdateViewCommand}"
CommandParameter="Settings" />
<Button x:Name="Btn"
Width="80"
Height="20"
FontSize="12"
Grid.Column="1"
Margin="10,5,110,0"
Content="TEST"
Command="{Binding UpdateViewCommand}"
CommandParameter="Settings" />
like i said before normal button works and with code of this button i was checking if i have done something wrong but everything looks fine Okay i found solution i needed to delete DataContext in xaml from button and add for every binding ElementName
Accord
Accord2y 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