WPF button content (vector drawing) not visible
I have in resource dictionary Buttons.xml
two vector drawings for to be shown as a button content.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox
x:Key="BlueMinusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Blue" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
<Viewbox
x:Key="GreenPlusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Green" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
<Line
X1="50"
X2="50"
Y1="10"
Y2="90"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
</ResourceDictionary>
In view1.xaml
I have three buttons and other controls and I use from resources same content for two buttons.
<UserControl
x:Class="ApplicationName.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ApplicationName">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Buttons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Content="Object1" />
<Button
Grid.Column="1"
Grid.Row="0"
Content="{StaticResource BlueMinusButton}"
Command="{Binding DoCommand1}" />
<Label
Grid.Column="0"
Grid.Row="1"
Content="Object2" />
<Button
Grid.Column="1"
Grid.Row="1"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand2}" />
<Label
Grid.Column="0"
Grid.Row="2"
Content="Object3" />
<Button
Grid.Column="1"
Grid.Row="2"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand3}" />
</Grid>
</UserControl>
view1.xaml
is used in view2.xaml
.
<UserControl
x:Class="ApplicationName.View2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="ApplicationName">
<Grid>
<StackPanel>
<Label
Content="Controls" />
<local:View1
DataContext="{Binding View1Context}"/>
<Label
Content="Other controls" />
</StackPanel>
</Grid>
</UserControl>
Here comes the problem: When looking the view2.xaml
in xaml editor, the content for the middle button is missing. Same happens in run time. If I look view1.xaml
in xaml editor, all the button contents are visible. Here is a picture from the views:
Why the content is not shown and how do I get it back?
wpf xaml
add a comment |
I have in resource dictionary Buttons.xml
two vector drawings for to be shown as a button content.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox
x:Key="BlueMinusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Blue" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
<Viewbox
x:Key="GreenPlusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Green" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
<Line
X1="50"
X2="50"
Y1="10"
Y2="90"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
</ResourceDictionary>
In view1.xaml
I have three buttons and other controls and I use from resources same content for two buttons.
<UserControl
x:Class="ApplicationName.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ApplicationName">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Buttons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Content="Object1" />
<Button
Grid.Column="1"
Grid.Row="0"
Content="{StaticResource BlueMinusButton}"
Command="{Binding DoCommand1}" />
<Label
Grid.Column="0"
Grid.Row="1"
Content="Object2" />
<Button
Grid.Column="1"
Grid.Row="1"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand2}" />
<Label
Grid.Column="0"
Grid.Row="2"
Content="Object3" />
<Button
Grid.Column="1"
Grid.Row="2"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand3}" />
</Grid>
</UserControl>
view1.xaml
is used in view2.xaml
.
<UserControl
x:Class="ApplicationName.View2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="ApplicationName">
<Grid>
<StackPanel>
<Label
Content="Controls" />
<local:View1
DataContext="{Binding View1Context}"/>
<Label
Content="Other controls" />
</StackPanel>
</Grid>
</UserControl>
Here comes the problem: When looking the view2.xaml
in xaml editor, the content for the middle button is missing. Same happens in run time. If I look view1.xaml
in xaml editor, all the button contents are visible. Here is a picture from the views:
Why the content is not shown and how do I get it back?
wpf xaml
Since your drawing resources are UI element, you should setx:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.
– Clemens
Nov 17 '18 at 7:58
add a comment |
I have in resource dictionary Buttons.xml
two vector drawings for to be shown as a button content.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox
x:Key="BlueMinusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Blue" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
<Viewbox
x:Key="GreenPlusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Green" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
<Line
X1="50"
X2="50"
Y1="10"
Y2="90"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
</ResourceDictionary>
In view1.xaml
I have three buttons and other controls and I use from resources same content for two buttons.
<UserControl
x:Class="ApplicationName.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ApplicationName">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Buttons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Content="Object1" />
<Button
Grid.Column="1"
Grid.Row="0"
Content="{StaticResource BlueMinusButton}"
Command="{Binding DoCommand1}" />
<Label
Grid.Column="0"
Grid.Row="1"
Content="Object2" />
<Button
Grid.Column="1"
Grid.Row="1"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand2}" />
<Label
Grid.Column="0"
Grid.Row="2"
Content="Object3" />
<Button
Grid.Column="1"
Grid.Row="2"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand3}" />
</Grid>
</UserControl>
view1.xaml
is used in view2.xaml
.
<UserControl
x:Class="ApplicationName.View2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="ApplicationName">
<Grid>
<StackPanel>
<Label
Content="Controls" />
<local:View1
DataContext="{Binding View1Context}"/>
<Label
Content="Other controls" />
</StackPanel>
</Grid>
</UserControl>
Here comes the problem: When looking the view2.xaml
in xaml editor, the content for the middle button is missing. Same happens in run time. If I look view1.xaml
in xaml editor, all the button contents are visible. Here is a picture from the views:
Why the content is not shown and how do I get it back?
wpf xaml
I have in resource dictionary Buttons.xml
two vector drawings for to be shown as a button content.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox
x:Key="BlueMinusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Blue" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
<Viewbox
x:Key="GreenPlusButton"
Height="20"
Stretch="Uniform">
<Canvas
Width="100"
Height="100">
<Canvas.LayoutTransform>
<ScaleTransform
ScaleX="1"
ScaleY="-1"
CenterX=".5"
CenterY=".5" />
</Canvas.LayoutTransform>
<Ellipse
Canvas.Left="0"
Canvas.Top="0"
Height="100"
Width="100"
Fill="Green" />
<Line
X1="10"
X2="90"
Y1="50"
Y2="50"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
<Line
X1="50"
X2="50"
Y1="10"
Y2="90"
Fill="Black"
StrokeThickness="10"
Stroke="Black" />
</Canvas>
</Viewbox>
</ResourceDictionary>
In view1.xaml
I have three buttons and other controls and I use from resources same content for two buttons.
<UserControl
x:Class="ApplicationName.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ApplicationName">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Buttons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Content="Object1" />
<Button
Grid.Column="1"
Grid.Row="0"
Content="{StaticResource BlueMinusButton}"
Command="{Binding DoCommand1}" />
<Label
Grid.Column="0"
Grid.Row="1"
Content="Object2" />
<Button
Grid.Column="1"
Grid.Row="1"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand2}" />
<Label
Grid.Column="0"
Grid.Row="2"
Content="Object3" />
<Button
Grid.Column="1"
Grid.Row="2"
Content="{StaticResource GreenPlusButton}"
Command="{Binding DoCommand3}" />
</Grid>
</UserControl>
view1.xaml
is used in view2.xaml
.
<UserControl
x:Class="ApplicationName.View2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="ApplicationName">
<Grid>
<StackPanel>
<Label
Content="Controls" />
<local:View1
DataContext="{Binding View1Context}"/>
<Label
Content="Other controls" />
</StackPanel>
</Grid>
</UserControl>
Here comes the problem: When looking the view2.xaml
in xaml editor, the content for the middle button is missing. Same happens in run time. If I look view1.xaml
in xaml editor, all the button contents are visible. Here is a picture from the views:
Why the content is not shown and how do I get it back?
wpf xaml
wpf xaml
asked Nov 17 '18 at 7:03
PAsko
122
122
Since your drawing resources are UI element, you should setx:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.
– Clemens
Nov 17 '18 at 7:58
add a comment |
Since your drawing resources are UI element, you should setx:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.
– Clemens
Nov 17 '18 at 7:58
Since your drawing resources are UI element, you should set
x:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.– Clemens
Nov 17 '18 at 7:58
Since your drawing resources are UI element, you should set
x:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.– Clemens
Nov 17 '18 at 7:58
add a comment |
1 Answer
1
active
oldest
votes
Set x:Shared="False"
for your each ViewBox
if you want to useit in multiple places.
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%2f53349023%2fwpf-button-content-vector-drawing-not-visible%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
Set x:Shared="False"
for your each ViewBox
if you want to useit in multiple places.
add a comment |
Set x:Shared="False"
for your each ViewBox
if you want to useit in multiple places.
add a comment |
Set x:Shared="False"
for your each ViewBox
if you want to useit in multiple places.
Set x:Shared="False"
for your each ViewBox
if you want to useit in multiple places.
answered Nov 18 '18 at 14:41
Shubham Sahu
1,1821828
1,1821828
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53349023%2fwpf-button-content-vector-drawing-not-visible%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
Since your drawing resources are UI element, you should set
x:Shared="True"
as explained e.g. here: stackoverflow.com/a/22960568/1136211. Even better would be to declare them as DrawingImages, and use them with an Image element or an ImageBrush.– Clemens
Nov 17 '18 at 7:58