【发布时间】:2014-08-18 13:21:21
【问题描述】:
我正在尝试制作一个桌面覆盖应用程序(想想雨量计),因为背景可以改变,我希望能够改变应用程序中文本的一般颜色和 alpha 值。
所以在设置菜单中,我想要一个 OnValueChanged 在静态类中设置属性的滑块,并且许多控件的不透明度绑定到该属性。为了使这更加复杂(也许?),应用程序同时打开了多个窗口。我没有绑定经验,无法使用。
到目前为止我的代码:
VisualSettings.cs
namespace ProjectSideBar
{
public class VisualSettings
{
public static double Opacity { get; set; }
}
}
MainWindow.xaml
<Window x:Class="ProjectSideBar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PSB="clr-namespace:ProjectSideBar"
Title="MainWindow" Height="1080" Width="300" ResizeMode="NoResize" ShowInTaskbar="False" WindowStyle="None" Closing="Window_Closing_1" Loaded="Window_Loaded" Background="Transparent" >
<Window.Resources>
<PSB:VisualSettings x:Key="VisualSettings"/>
</Window.Resources>
<Grid>
<TextBlock x:Name="ClockTB" HorizontalAlignment="Left" TextWrapping="Wrap" Text="22:22:22" VerticalAlignment="Top" Height="84" Width="300" Cursor="None" Foreground="White" FontSize="48" FontFamily="BatmanForeverAlternate" TextAlignment="Center" Opacity="{Binding Source={StaticResource VisualSettings} , Path=Opacity}" Margin="0,22,0,0" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1.5"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
<Slider x:Name="TestSlider" HorizontalAlignment="Left" Margin="10,1052,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.611" Width="172" Foreground="#FF122268" ValueChanged="TestSlider_ValueChanged" LargeChange="0.1" SmallChange="0.01" Maximum="1" Value="0.65"/>
</Grid>
</Window>
MainWindow.xaml.cs
private void TestSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
VisualSettings.Opacity = TestSlider.Value;
}
谁能帮帮我?
亲切的问候,RoXaS
【问题讨论】:
-
此链接here 将帮助您入门。
-
@RohitVats 谢谢,完美运行。如果您将此添加为答案,我会接受。