Skip to content

Commit efff571

Browse files
committed
Added manual selection of grid color
1 parent 836ee36 commit efff571

4 files changed

Lines changed: 102 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace ScreenGrid.ViewModels
2+
{
3+
using System.Linq;
4+
using System.Windows.Media;
5+
6+
public class ColorItemViewModel
7+
{
8+
private Color color;
9+
10+
public ColorItemViewModel(Color color)
11+
{
12+
this.color = color;
13+
}
14+
15+
public Color Color
16+
{
17+
get
18+
{
19+
return this.color;
20+
}
21+
}
22+
23+
public Brush Brush
24+
{
25+
get
26+
{
27+
return new SolidColorBrush(this.Color);
28+
}
29+
}
30+
31+
public string Name
32+
{
33+
get
34+
{
35+
return GetColorName(this.Color);
36+
}
37+
}
38+
39+
private static string GetColorName(Color color)
40+
{
41+
var colorProperty = typeof(Colors).GetProperties()
42+
.FirstOrDefault(p => (Color)p.GetValue(null, null) == color);
43+
return colorProperty != null ? colorProperty.Name : "???";
44+
}
45+
}
46+
}

Src/ScreenGrid.ViewModels/ScreenGrid.ViewModels.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<Reference Include="WindowsBase" />
4242
</ItemGroup>
4343
<ItemGroup>
44+
<Compile Include="ColorItemViewModel.cs" />
4445
<Compile Include="ScreenGridViewModel.cs" />
4546
<Compile Include="Properties\AssemblyInfo.cs" />
4647
<Compile Include="Utils\BaseNotifyPropertyChanged.cs" />

Src/ScreenGrid.ViewModels/ScreenGridViewModel.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,45 @@ private bool FlipV
107107
}
108108
}
109109

110+
private Color selectedLineColor = Colors.White;
111+
112+
private static readonly List<Color> lineColors = new List<Color>(new[]
113+
{
114+
Colors.White,
115+
Colors.Magenta,
116+
Colors.Black,
117+
});
118+
119+
public IList<ColorItemViewModel> LineColors
120+
{
121+
get
122+
{
123+
return lineColors.Select(c => new ColorItemViewModel(c)).ToList();
124+
}
125+
}
126+
127+
public ColorItemViewModel SelectedLineColor
128+
{
129+
get
130+
{
131+
return new ColorItemViewModel(this.selectedLineColor);
132+
}
133+
134+
set
135+
{
136+
if (this.selectedLineColor != value.Color)
137+
{
138+
this.selectedLineColor = value.Color;
139+
this.UpdateContentControl();
140+
}
141+
}
142+
}
143+
110144
private Brush LineBrush
111145
{
112146
get
113147
{
114-
return new SolidColorBrush(Colors.White) { Opacity = 0.8 };
148+
return new SolidColorBrush(this.selectedLineColor) { Opacity = 0.75 };
115149
}
116150
}
117151

Src/ScreenGrid.Views/ScreenGridWindow.xaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,26 @@
9494
Width="200"
9595
HorizontalAlignment="Stretch"
9696
MouseDown="Window_MouseDown" />
97-
<TextBlock VerticalAlignment="Center" Margin="8,0,0,0"
97+
<ComboBox HorizontalAlignment="Left" VerticalAlignment="Center"
98+
Width="85" Height="20"
99+
FontSize="10"
100+
ItemsSource="{Binding LineColors, Mode=OneTime}"
101+
SelectedItem="{Binding SelectedLineColor, Mode=TwoWay}">
102+
<ComboBox.ItemTemplate>
103+
<DataTemplate>
104+
<StackPanel Orientation="Horizontal" Margin="2">
105+
<Rectangle Stroke="Black"
106+
SnapsToDevicePixels="True"
107+
Width="12" Height="8"
108+
Fill="{Binding Path=Brush}" />
109+
<TextBlock Margin="4 0 2 0" VerticalAlignment="Center"
110+
Text="{Binding Path=Name}"/>
111+
</StackPanel>
112+
</DataTemplate>
113+
</ComboBox.ItemTemplate>
114+
</ComboBox>
115+
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center"
116+
Margin="88,0,0,0"
98117
IsHitTestVisible="False"
99118
ToolTip="Size of grid internal area"
100119
Text="{Binding CaptionText}" />

0 commit comments

Comments
 (0)