C
C#2y ago
Elio

✅ WPF XAML Designer

Hello, my xaml designer do not work but i can't figure it out why. There is an exception which say it's not able to find the resource " 'resources/images/png/manual/[email protected]'" but this resource isn't use in my page, this resource is used in the UC which is in this page. the fact is that my xaml designer work well for the UC but when i add this UC to the page, the xaml designer of the page trigger an exception. The app have no problem when i run it i just want to know why the xaml designer trigged and exception
34 Replies
Buddy
Buddy2y ago
Do not use the designer $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
Buddy
Buddy2y ago
Margin is the spacing between elements, it is not absolute position or relative So if you resize the app, UI will mess up immediately.
Elio
ElioOP2y ago
thanks but how i am supposed to add a space of 5 between each element without using margin ?
Buddy
Buddy2y ago
You must use layout controls.
Elio
ElioOP2y ago
i will keep this seems to be really useful 😮
Buddy
Buddy2y ago
And Margin is fine if it's below 30.
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
Also you have hot reload, which means you can just run the app and change the XAML, and the running app will change immediately upon file save.
Elio
ElioOP2y ago
i already knew that i use it everytime ahah ok so i'll keep it in mind that xaml designer sucks
Buddy
Buddy2y ago
But regarding the image not being found, is it marked as a resource?
Elio
ElioOP2y ago
yup everything work but when i had the usercontrol to my page it says that the resource isn't find and i don't know why the page try to find it if it's in the usercontrol
Elio
ElioOP2y ago
Buddy
Buddy2y ago
Have you tried renaming it to something that doesn't contain special characters? Something common like Material1.png
Elio
ElioOP2y ago
no i didn't tried cause my UC didn't trigger any exception and the image was well displayed but i'll try
Elio
ElioOP2y ago
Elio
ElioOP2y ago
same error impossible to find the resource
Buddy
Buddy2y ago
Wait, how do you load it? and where Please show the XAML $code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Buddy
Buddy2y ago
replace cs with xml (easier to read)
Elio
ElioOP2y ago
BlazeBin - bmhufnfyxvbl
A tool for sharing your source code with the world!
Elio
ElioOP2y ago
what i've called page is the one containing the UC which trigger the exception
Buddy
Buddy2y ago
Is it an image component?
Elio
ElioOP2y ago
the UC which is the problem is MaterialDetailsView
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Image x:Name="Icon" Source="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Image x:Name="Icon" Source="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
my button style nop i just add an image in the background of a button
Buddy
Buddy2y ago
Tag?
Elio
ElioOP2y ago
i found this solution to set an image in the background of the button i don't know what's really tag 😅
<Button Style="{StaticResource CircularImageButtonStyle}"
HorizontalAlignment="Left" VerticalAlignment="Top"
Tag="{StaticResource MaterialType}" Margin="10,140,0,0"/>
<Button Style="{StaticResource CircularImageButtonStyle}"
HorizontalAlignment="Left" VerticalAlignment="Top"
Tag="{StaticResource MaterialType}" Margin="10,140,0,0"/>
here is how i use the button
Buddy
Buddy2y ago
I would just set the Content directly rather than to use Tag
Elio
ElioOP2y ago
in the content ?
Buddy
Buddy2y ago
Tag is a boxed value of type object
Elio
ElioOP2y ago
<Button Style="{StaticResource CircularImageButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,140,0,0"> <Image x:Name="image" Source="{StaticResource MaterialType}" /> </Button> like this ?
Buddy
Buddy2y ago
Sure
Elio
ElioOP2y ago
ok it simplier than what i was trying to do 😂 i will try this to see if it resolve my problem ok that's better thanks i will keep this then
Buddy
Buddy2y ago
blobthumbsup
Elio
ElioOP2y ago
and i won't forget to save this to not forget it 🙂 thanks !
Buddy
Buddy2y ago
Anytime. Good luck.
Want results from more Discord servers?
Add your server