首页 > 代码库 > 动态调色板
动态调色板
今天抽空做了一个简单的动态的调色板,当做对MVVM的复习吧
效果如下:
功能比较简单,通过调节滑块来调节A,R,G,B的值来改变窗口的透明度和颜色,颜色的绑定上,还没找到更好的方案来改变笔刷的值
主要代码如下:
<Window.Resources> <Style TargetType="Slider"> <Setter Property="IsSnapToTickEnabled" Value="http://www.mamicode.com/True"/> <Setter Property="TickFrequency" Value="http://www.mamicode.com/1"/> <Setter Property="Minimum" Value="http://www.mamicode.com/0"/> <Setter Property="Maximum" Value="http://www.mamicode.com/255"/> <Setter Property="VerticalAlignment" Value="http://www.mamicode.com/Center"/> <Setter Property="Margin" Value="http://www.mamicode.com/10,0"/> </Style> <Style TargetType="TextBlock"> <Setter Property="VerticalAlignment" Value="http://www.mamicode.com/Center"/> </Style> </Window.Resources>
<Border Name="border1" BorderBrush="{Binding ColorBrush}" BorderThickness="4" CornerRadius="10" Padding="8" PreviewMouseLeftButtonDown="border1_PreviewMouseLeftButtonDown"> <Border BorderBrush="{Binding ColorBrush}" BorderThickness="6" CornerRadius="8"> <Grid Background="{Binding ColorBrush}" > <Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"></ColumnDefinition> <ColumnDefinition Width="200"></ColumnDefinition> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Text="Alpha" HorizontalAlignment="Right"/> <TextBlock Text="R" Grid.Row="1" HorizontalAlignment="Right" /> <TextBlock Text="G" Grid.Row="2" HorizontalAlignment="Right"/> <TextBlock Text="B" Grid.Row="3" HorizontalAlignment="Right" /> <Slider Grid.Column="1" Value=http://www.mamicode.com/"{Binding A}" Name="slider1" /> <Slider Grid.Row="1" Grid.Column="1" Value=http://www.mamicode.com/"{Binding R}" Name="slider2"/> <Slider Grid.Row="2" Grid.Column="1" Value=http://www.mamicode.com/"{Binding G}" Name="slider3"/> <Slider Grid.Row="3" Grid.Column="1" Value=http://www.mamicode.com/"{Binding B}" Name="slider4"/> <TextBlock Text="{Binding ElementName=slider1,Path=Value,UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" /> <TextBlock Text="{Binding ElementName=slider2,Path=Value,UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="2" /> <TextBlock Text="{Binding ElementName=slider3,Path=Value,UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="2" /> <TextBlock Text="{Binding ElementName=slider4,Path=Value,UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" Grid.Column="2" /> </Grid> </Border> </Border>
下载 动态调色板
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。