C
C#13mo ago
bribri

❔ WPF application resources not found in window

I'm doing a small project but for reason I can't use my WPF application resources in my windows. I have done it before and looking at my other projects so find what I do wrong but everything seems to be the same... I'm using a 3 layer architecture. Where my notes.startup start everything up and the start.xaml file is my wpf window. it starts the window but when I want to add a style I get an "resource could not be resolved" error. Because the window opens I guess almost everything works but I probably forgot something small Start.xaml
<Window x:Class="Notes.Presentation.Start"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:local="clr-namespace:Notes.Presentation"
mc:Ignorable="d"
Title="Start" Height="450" Width="800"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
Style="{StaticResource StandaardWindow}"
>
<Grid>
</Grid>
</Window>
<Window x:Class="Notes.Presentation.Start"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:local="clr-namespace:Notes.Presentation"
mc:Ignorable="d"
Title="Start" Height="450" Width="800"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
Style="{StaticResource StandaardWindow}"
>
<Grid>
</Grid>
</Window>
app.xaml
<Application x:Class="Notes.Startup.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=System.Runtime"
xmlns:local="clr-namespace:Notes.Startup"
Startup="Application_Startup">
<Application.Resources>


<Style TargetType="Window" x:Key="StandaardWindow">
<Setter Property="Height" Value="600"/>
<Setter Property="Width" Value="1400"/>

</Style>

</Application.Resources>

</Application>
<Application x:Class="Notes.Startup.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=System.Runtime"
xmlns:local="clr-namespace:Notes.Startup"
Startup="Application_Startup">
<Application.Resources>


<Style TargetType="Window" x:Key="StandaardWindow">
<Setter Property="Height" Value="600"/>
<Setter Property="Width" Value="1400"/>

</Style>

</Application.Resources>

</Application>
11 Replies
bribri
bribri13mo ago
Now it works if I build the code but not in my preview. (The style gives it a blue background)
Buddy
Buddy13mo ago
Do not rely on designer please $rulesofwpf
MODiX
MODiX13mo 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
bribri
bribri13mo ago
Is it so bad? for bugs etc
Buddy
Buddy13mo ago
It's awful. Hot reload is significantly better. Just debug your app and change the XAML at runtime, when you save it is reflected immediately for the debugged app.
bribri
bribri13mo ago
my first problems where in the XAML ... But I think with a build it fixed itself
Buddy
Buddy13mo ago
Yes. That is a must. You have to build first for everything regarding intellisense to update.
bribri
bribri13mo ago
Oh ok! Just starting with UI and seems buggier then just (simple) console apps. I guess because I do alot of console logs so it rebuilds more
Mayor McCheese
Mayor McCheese13mo ago
I used to use the designer as a xaml replica for roughing things in, but really like was stated, the designer in WPF is a hot mess; it's never gotten better since day 1.
Buddy
Buddy13mo ago
tbh designer in XAML shouldn't exist. Only preview should exist.
Accord
Accord13mo 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.