如何在StackPanel中设置背景

发布于 2024-09-24 14:27:03 字数 1123 浏览 5 评论 0原文

请任何人告诉我如何在 xaml 中的堆栈面板背景中设置图像?我已经尝试过以下操作,它引发了 Background 没有属性 Image 的错误

   <Button.ToolTip>
        <StackPanel Height="200" Width="200">
            <StackPanel Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                <StackPanel.Background>
                    <Image Source="E:\R\watermark9.bmp"></Image>
                </StackPanel.Background>
                <Image VerticalAlignment="Top"  Width="30" Height="30" Source="E:\My Projects\Interconnect_New\Interconnect\Resources\watermark9.bmp" Name="image1" />
                <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="143">
                    <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text="Hello! Fancy Tip" />
                </TextBlock>
            </StackPanel>
          </StackPanel>
    </Button.ToolTip>

Please anyone let me know how to set image in stack panel background in xaml ? I have already tried the following it throwing an error that Background does not have property Image

   <Button.ToolTip>
        <StackPanel Height="200" Width="200">
            <StackPanel Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                <StackPanel.Background>
                    <Image Source="E:\R\watermark9.bmp"></Image>
                </StackPanel.Background>
                <Image VerticalAlignment="Top"  Width="30" Height="30" Source="E:\My Projects\Interconnect_New\Interconnect\Resources\watermark9.bmp" Name="image1" />
                <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="143">
                    <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text="Hello! Fancy Tip" />
                </TextBlock>
            </StackPanel>
          </StackPanel>
    </Button.ToolTip>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2024-10-01 14:27:03

试试这个

<Button.ToolTip>
    <StackPanel Height="200" Width="200">
        <StackPanel Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
            <StackPanel.Background>
                <ImageBrush ImageSource="E:\R\watermark9.bmp" />
            </StackPanel.Background>
            <Image VerticalAlignment="Top"  Width="30" Height="30" Source="E:\My Projects\Interconnect_New\Interconnect\Resources\watermark9.bmp" Name="image1" />
            <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="143">                    <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text="Hello! Fancy Tip" /></TextBlock>
        </StackPanel> 
    </StackPanel>
</Button.ToolTip>

Try this

<Button.ToolTip>
    <StackPanel Height="200" Width="200">
        <StackPanel Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
            <StackPanel.Background>
                <ImageBrush ImageSource="E:\R\watermark9.bmp" />
            </StackPanel.Background>
            <Image VerticalAlignment="Top"  Width="30" Height="30" Source="E:\My Projects\Interconnect_New\Interconnect\Resources\watermark9.bmp" Name="image1" />
            <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="143">                    <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text="Hello! Fancy Tip" /></TextBlock>
        </StackPanel> 
    </StackPanel>
</Button.ToolTip>
讽刺将军 2024-10-01 14:27:03

您需要使用图像画笔

You need to use an image brush

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文