Visualbrush binding in a style System.Windows.Data Error: 2 Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Binding GradientStop works but reports errorBinding ItemsSource of a ComboBoxColumn in WPF DataGridWPF Error: Cannot find governing FrameworkElement for target elementDataGridTextColumn binding issueBinding to TemplatedParent within a ControlTemplate.ResourcesWhy does this example produce so many binding errors?WPF datagrid.rowstyle bindingBind from ControlTemplate to ViewModelDataGridComboBoxColumn.ItemsSource. Binding vs EditingElementStyleAvalonDock Databind System.Windows.Data Error: 2
Why I cannot instantiate a class whose constructor is private in a friend class?
Why isn't everyone flabbergasted about Bran's "gift"?
Coin Game with infinite paradox
Will temporary Dex penalties prevent you from getting the benefits of the "Two Weapon Fighting" feat if your Dex score falls below the prerequisite?
Protagonist's race is hidden - should I reveal it?
What is the definining line between a helicopter and a drone a person can ride in?
What is ls Largest Number Formed by only moving two sticks in 508?
false 'Security alert' from Google - every login generates mails from 'no-reply@accounts.google.com'
What's called a person who works as someone who puts products on shelves in stores?
Could a cockatrice have parasitic embryos?
Why did Europeans not widely domesticate foxes?
What were wait-states, and why was it only an issue for PCs?
RIP Packet Format
When I export an AI 300x60 art board it saves with bigger dimensions
How to keep bees out of canned beverages?
How do I deal with an erroneously large refund?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Is a self contained air-bullet cartridge feasible?
Was Objective-C really a hindrance to Apple software development?
How long can a nation maintain a technological edge over the rest of the world?
SQL Server placement of master database files vs resource database files
/bin/ls sorts differently than just ls
What is the ongoing value of the Kanban board to the developers as opposed to management
Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?
Visualbrush binding in a style System.Windows.Data Error: 2
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Binding GradientStop works but reports errorBinding ItemsSource of a ComboBoxColumn in WPF DataGridWPF Error: Cannot find governing FrameworkElement for target elementDataGridTextColumn binding issueBinding to TemplatedParent within a ControlTemplate.ResourcesWhy does this example produce so many binding errors?WPF datagrid.rowstyle bindingBind from ControlTemplate to ViewModelDataGridComboBoxColumn.ItemsSource. Binding vs EditingElementStyleAvalonDock Databind System.Windows.Data Error: 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I just have a simple binding, it works well but there is an error popup.
The effects work but still an error.
And the error is
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'VisualBrush' (HashCode=23487194); target property is 'Visual' (type 'Visual')
I have tried x: Reference but there would be another error.
Appreciated a lot if any can help.
<Style TargetType="x:Type Window">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
c# wpf xaml binding visualbrush
add a comment |
I just have a simple binding, it works well but there is an error popup.
The effects work but still an error.
And the error is
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'VisualBrush' (HashCode=23487194); target property is 'Visual' (type 'Visual')
I have tried x: Reference but there would be another error.
Appreciated a lot if any can help.
<Style TargetType="x:Type Window">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
c# wpf xaml binding visualbrush
add a comment |
I just have a simple binding, it works well but there is an error popup.
The effects work but still an error.
And the error is
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'VisualBrush' (HashCode=23487194); target property is 'Visual' (type 'Visual')
I have tried x: Reference but there would be another error.
Appreciated a lot if any can help.
<Style TargetType="x:Type Window">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
c# wpf xaml binding visualbrush
I just have a simple binding, it works well but there is an error popup.
The effects work but still an error.
And the error is
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'VisualBrush' (HashCode=23487194); target property is 'Visual' (type 'Visual')
I have tried x: Reference but there would be another error.
Appreciated a lot if any can help.
<Style TargetType="x:Type Window">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
c# wpf xaml binding visualbrush
c# wpf xaml binding visualbrush
asked Mar 9 at 4:41
Will ZhangWill Zhang
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Re templating a window like that is not really the way I'd go about this sort of thing.
I'd use something more like the approach in this sample:
https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe
Finished fancy window is
Window6, using WindowChrome styling which is in the resource dictionary Dictionary1.
Which has stuff lika a big round close button. But to give you the idea before downloading:
<Style x:Key="FinishedWindow" TargetType="x:Type Window">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="StaticResource DarkDark"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="20"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border Background="StaticResource BrightMid" BorderBrush="StaticResource DarkLight" BorderThickness="4,4,6,6"
CornerRadius="12">
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
</Border.Effect>
</Border>
<Border BorderBrush="StaticResource DarkDark" BorderThickness="2"
CornerRadius="12" ClipToBounds="True">
</Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Binding RelativeSource=RelativeSource TemplatedParent, Path=Title"
Foreground="StaticResource DarkDark"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontWeight="Bold"
FontSize="16"
/>
<Button Name="CloseButton"
Width="20" Height="20"
Grid.Row="0"
HorizontalAlignment="Right"
BorderThickness="0"
Margin="0,12,12,0"
Command="Binding RelativeSource=RelativeSource TemplatedParent, Path=CloseCommand"
Style="StaticResource CloseButton"/>
<ContentPresenter Grid.Row="1" Margin="12"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
I gave your style a go.
Just using it implicitly had no effect at all.
I put it in app.xaml and gave it a key
<Application.Resources>
<Style TargetType="x:Type Window" x:Key="roundedWindowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And then I applied that to mainwindow
<Window
...
Title="MainWindow"
Style="StaticResource roundedWindowStyle"
Hit f5... and it kind of works. Well.
If you ignore that window chrome means it cannot work as you seem to intend.
You probably ought to be looking at using window chrome instead.
With what you have there.
At the absolute minimum, you need a Contentpresenter inside that Grid.
Because a window is a content control but it won't show any content at all if you have no contentpresenter in the template.
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074043%2fvisualbrush-binding-in-a-style-system-windows-data-error-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Re templating a window like that is not really the way I'd go about this sort of thing.
I'd use something more like the approach in this sample:
https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe
Finished fancy window is
Window6, using WindowChrome styling which is in the resource dictionary Dictionary1.
Which has stuff lika a big round close button. But to give you the idea before downloading:
<Style x:Key="FinishedWindow" TargetType="x:Type Window">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="StaticResource DarkDark"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="20"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border Background="StaticResource BrightMid" BorderBrush="StaticResource DarkLight" BorderThickness="4,4,6,6"
CornerRadius="12">
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
</Border.Effect>
</Border>
<Border BorderBrush="StaticResource DarkDark" BorderThickness="2"
CornerRadius="12" ClipToBounds="True">
</Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Binding RelativeSource=RelativeSource TemplatedParent, Path=Title"
Foreground="StaticResource DarkDark"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontWeight="Bold"
FontSize="16"
/>
<Button Name="CloseButton"
Width="20" Height="20"
Grid.Row="0"
HorizontalAlignment="Right"
BorderThickness="0"
Margin="0,12,12,0"
Command="Binding RelativeSource=RelativeSource TemplatedParent, Path=CloseCommand"
Style="StaticResource CloseButton"/>
<ContentPresenter Grid.Row="1" Margin="12"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
I gave your style a go.
Just using it implicitly had no effect at all.
I put it in app.xaml and gave it a key
<Application.Resources>
<Style TargetType="x:Type Window" x:Key="roundedWindowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And then I applied that to mainwindow
<Window
...
Title="MainWindow"
Style="StaticResource roundedWindowStyle"
Hit f5... and it kind of works. Well.
If you ignore that window chrome means it cannot work as you seem to intend.
You probably ought to be looking at using window chrome instead.
With what you have there.
At the absolute minimum, you need a Contentpresenter inside that Grid.
Because a window is a content control but it won't show any content at all if you have no contentpresenter in the template.
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
add a comment |
Re templating a window like that is not really the way I'd go about this sort of thing.
I'd use something more like the approach in this sample:
https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe
Finished fancy window is
Window6, using WindowChrome styling which is in the resource dictionary Dictionary1.
Which has stuff lika a big round close button. But to give you the idea before downloading:
<Style x:Key="FinishedWindow" TargetType="x:Type Window">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="StaticResource DarkDark"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="20"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border Background="StaticResource BrightMid" BorderBrush="StaticResource DarkLight" BorderThickness="4,4,6,6"
CornerRadius="12">
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
</Border.Effect>
</Border>
<Border BorderBrush="StaticResource DarkDark" BorderThickness="2"
CornerRadius="12" ClipToBounds="True">
</Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Binding RelativeSource=RelativeSource TemplatedParent, Path=Title"
Foreground="StaticResource DarkDark"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontWeight="Bold"
FontSize="16"
/>
<Button Name="CloseButton"
Width="20" Height="20"
Grid.Row="0"
HorizontalAlignment="Right"
BorderThickness="0"
Margin="0,12,12,0"
Command="Binding RelativeSource=RelativeSource TemplatedParent, Path=CloseCommand"
Style="StaticResource CloseButton"/>
<ContentPresenter Grid.Row="1" Margin="12"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
I gave your style a go.
Just using it implicitly had no effect at all.
I put it in app.xaml and gave it a key
<Application.Resources>
<Style TargetType="x:Type Window" x:Key="roundedWindowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And then I applied that to mainwindow
<Window
...
Title="MainWindow"
Style="StaticResource roundedWindowStyle"
Hit f5... and it kind of works. Well.
If you ignore that window chrome means it cannot work as you seem to intend.
You probably ought to be looking at using window chrome instead.
With what you have there.
At the absolute minimum, you need a Contentpresenter inside that Grid.
Because a window is a content control but it won't show any content at all if you have no contentpresenter in the template.
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
add a comment |
Re templating a window like that is not really the way I'd go about this sort of thing.
I'd use something more like the approach in this sample:
https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe
Finished fancy window is
Window6, using WindowChrome styling which is in the resource dictionary Dictionary1.
Which has stuff lika a big round close button. But to give you the idea before downloading:
<Style x:Key="FinishedWindow" TargetType="x:Type Window">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="StaticResource DarkDark"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="20"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border Background="StaticResource BrightMid" BorderBrush="StaticResource DarkLight" BorderThickness="4,4,6,6"
CornerRadius="12">
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
</Border.Effect>
</Border>
<Border BorderBrush="StaticResource DarkDark" BorderThickness="2"
CornerRadius="12" ClipToBounds="True">
</Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Binding RelativeSource=RelativeSource TemplatedParent, Path=Title"
Foreground="StaticResource DarkDark"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontWeight="Bold"
FontSize="16"
/>
<Button Name="CloseButton"
Width="20" Height="20"
Grid.Row="0"
HorizontalAlignment="Right"
BorderThickness="0"
Margin="0,12,12,0"
Command="Binding RelativeSource=RelativeSource TemplatedParent, Path=CloseCommand"
Style="StaticResource CloseButton"/>
<ContentPresenter Grid.Row="1" Margin="12"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
I gave your style a go.
Just using it implicitly had no effect at all.
I put it in app.xaml and gave it a key
<Application.Resources>
<Style TargetType="x:Type Window" x:Key="roundedWindowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And then I applied that to mainwindow
<Window
...
Title="MainWindow"
Style="StaticResource roundedWindowStyle"
Hit f5... and it kind of works. Well.
If you ignore that window chrome means it cannot work as you seem to intend.
You probably ought to be looking at using window chrome instead.
With what you have there.
At the absolute minimum, you need a Contentpresenter inside that Grid.
Because a window is a content control but it won't show any content at all if you have no contentpresenter in the template.
Re templating a window like that is not really the way I'd go about this sort of thing.
I'd use something more like the approach in this sample:
https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe
Finished fancy window is
Window6, using WindowChrome styling which is in the resource dictionary Dictionary1.
Which has stuff lika a big round close button. But to give you the idea before downloading:
<Style x:Key="FinishedWindow" TargetType="x:Type Window">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="StaticResource DarkDark"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="20"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border Background="StaticResource BrightMid" BorderBrush="StaticResource DarkLight" BorderThickness="4,4,6,6"
CornerRadius="12">
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
</Border.Effect>
</Border>
<Border BorderBrush="StaticResource DarkDark" BorderThickness="2"
CornerRadius="12" ClipToBounds="True">
</Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Binding RelativeSource=RelativeSource TemplatedParent, Path=Title"
Foreground="StaticResource DarkDark"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontWeight="Bold"
FontSize="16"
/>
<Button Name="CloseButton"
Width="20" Height="20"
Grid.Row="0"
HorizontalAlignment="Right"
BorderThickness="0"
Margin="0,12,12,0"
Command="Binding RelativeSource=RelativeSource TemplatedParent, Path=CloseCommand"
Style="StaticResource CloseButton"/>
<ContentPresenter Grid.Row="1" Margin="12"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
I gave your style a go.
Just using it implicitly had no effect at all.
I put it in app.xaml and gave it a key
<Application.Resources>
<Style TargetType="x:Type Window" x:Key="roundedWindowStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Window">
<Grid>
<Border
x:Name="RoundMask"
CornerRadius="10"
Background="white"/>
<!-- The main content -->
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="Binding ElementName=RoundMask" />
</Grid.OpacityMask>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And then I applied that to mainwindow
<Window
...
Title="MainWindow"
Style="StaticResource roundedWindowStyle"
Hit f5... and it kind of works. Well.
If you ignore that window chrome means it cannot work as you seem to intend.
You probably ought to be looking at using window chrome instead.
With what you have there.
At the absolute minimum, you need a Contentpresenter inside that Grid.
Because a window is a content control but it won't show any content at all if you have no contentpresenter in the template.
answered Mar 9 at 10:52
AndyAndy
3,8761109
3,8761109
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
add a comment |
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
Hi Thank you for the reply, but this actually isn't the issue that I am facing, I didn't include the content part and the chrome part, but the problem is caused by VisualBrush, as using visual brush binding in a style will cause an exception.
– Will Zhang
Mar 9 at 19:44
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
See the second picture? Using the visual brush binding in a style. No exception.
– Andy
Mar 9 at 20:05
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
Hi Andy thank you so much, I think I know why this happened. It's because I pack ed this style in a dll,. If I put it in the app.xaml it works well. But since it's a messagebox I still want to put it in a dll for referencing.
– Will Zhang
Mar 10 at 1:23
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
And when the window inside the dll reference this style it will cause this error, but the other normal window can use this freely.
– Will Zhang
Mar 10 at 1:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074043%2fvisualbrush-binding-in-a-style-system-windows-data-error-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown