C
C#17mo 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
Buddy17mo ago
$rulesofwpf
MODiX
MODiX17mo 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
Buddy17mo ago
Please explain more in detail what the issue is
FaNim
FaNim17mo 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
Buddy17mo ago
Please post the code of that button $paste
MODiX
MODiX17mo 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
FaNim17mo ago
the most important references i send in pics
FaNim
FaNim17mo ago
BlazeBin - gtqvzzibjhfx
A tool for sharing your source code with the world!
Buddy
Buddy17mo ago
That says nothing, I'd like the full code of the button, not the XAML.
FaNim
FaNim17mo ago
I gave there full code for button with xaml in it
FaNim
FaNim17mo ago
I gave it in pastebin But maybe i gave you wrong link Ah okay i need to give link every class
FaNim
FaNim17mo ago
BlazeBin - ozbufzywpqjw
A tool for sharing your source code with the world!
FaNim
FaNim17mo 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
Accord17mo 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