简体   繁体   English

通过按钮单击事件设置应用程序的背景图像

[英]Set background image of app by a button click event

when a button is pressed ,the background image of the app must may be changed to a image in the project . 当按下按钮时,必须将应用程序的背景图像更改为项目中的图像。

i have tried to set the background image by modifying the visibility of a XAML image control whose source points to the image in the project .But the problem in this case is that the image hides some of the XAML controls on setting visibility = true . 我试图通过修改XAML图像控件的可见性来设置背景图像,该XAML图像控件的源指向项目中的图像。但是在这种情况下,问题在于,该图像隐藏了一些设置XVisibility = true的XAML控件。 I tried setting "send to back " and opacity options ,but no use in them . 我尝试设置“发送回”和不透明度选项,但没有用。

Please tell , if there is a solution for this problem or assist me in using the correct image XAML property to achieve my solution. 请告诉您是否有解决此问题的方法,或者帮助我使用正确的图像XAML属性来实现我的解决方案。

You can use the VisualBrush to set your image as the background of your root element (Grid in this case). 您可以使用VisualBrush将图像设置为根元素的背景(在这种情况下为网格)。 In your code, on button press set the BackgroundImage property to your image path and if you have some type of change notification for this property the image will be changed. 在代码中,按一下按钮,将BackgroundImage属性设置为图像路径,如果您对该属性具有某种类型的更改通知,则图像将被更改。

    <Grid.Background>
        <VisualBrush TileMode="None" Opacity="{Binding BackgroundOpacity}">
            <VisualBrush.Visual>
                <Image Source="{Binding BackgroundImage}"></Image>
            </VisualBrush.Visual>
        </VisualBrush>
    </Grid.Background>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM