如何将图像插入Generic.xaml

时间:2013-11-12 09:52:36

标签: c# wpf xaml

我使用generic.xaml为我正在创建的应用程序创建母版页,到目前为止这是代码:

    <Style TargetType="{x:Type local:Master}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:Master}">                   
                <StackPanel>
                    <Menu Height="50" Margin="0,0,0,0" HorizontalAlignment="Stretch" FlowDirection="RightToLeft" Panel.ZIndex="0">
                        <Menu.Background>
                            <LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
                                <GradientStop Color="#FFB3DDF2" Offset="1.0"/>
                                <GradientStop Color="#FFD6E9F4" Offset="0.0"/>
                            </LinearGradientBrush>
                        </Menu.Background>
                    </Menu>                       
                    <Menu Width="350" Height="850" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Left" FlowDirection="RightToLeft" DockPanel.Dock="Bottom" Panel.ZIndex="0">
                        <Menu.Background>
                            <LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
                                <GradientStop Color="#FFD6E9F4" Offset="1.0"/>
                                <GradientStop Color="White" Offset="0.0"/>
                            </LinearGradientBrush>
                        </Menu.Background>
                    </Menu> 
                </StackPanel>                                                            
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我想在此页面添加图片,我尝试了很多方法但找不到正确的方法。有些方法会将图像带入,但会删除我的其他菜单。

提前致谢。

1 个答案:

答案 0 :(得分:0)

将图像放入项目中并将其构建操作设置为Resource,然后以这种方式引用它:

<Image Source="/YourApplicatioName;component/PathToYourImage/Image.png" />