-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml
133 lines (123 loc) · 6.46 KB
/
MainWindow.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!--
Copyright 2018 Sedat Kapanoglu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Window x:Class="NoJoy.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NoJoy"
mc:Ignorable="d"
MinWidth="500"
Title="NoJoy" Height="350" Width="640" SizeToContent="WidthAndHeight" Loaded="Window_Loaded">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<ObjectDataProvider x:Key="Controllers"
MethodName="GetControllers"
ObjectType="{x:Type local:WmiControllerEnumerator}" />
<local:BoolToColorConverter x:Key="boolToColorConverter" />
<local:ErrorVisibilityConverter x:Key="errorVisibilityConverter" />
</Window.Resources>
<StackPanel Margin="10" DataContext="{Binding Source={StaticResource Controllers}}">
<TextBlock FontSize="24">Game Controllers</TextBlock>
<ItemsControl Margin="5"
DataContext="{Binding Path=Items}"
ItemsSource="{Binding}"
Focusable="False">
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Count}" Value="0">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="300" Margin="10,5,10,5" HorizontalAlignment="Center" MaxWidth="160">
<TextBlock Opacity="0.5"
Margin="10"
FontSize="70"
Text="🕹"
HorizontalAlignment="Center"></TextBlock>
<TextBlock FontSize="20" Text="{Binding Path=Name}"
HorizontalAlignment="Center"
Height="56"
TextWrapping="Wrap"
MaxWidth="160" ></TextBlock>
<Button x:Name="EnableDisableButton"
HorizontalAlignment="Center"
FontSize="15"
Margin="0,10,0,10"
Padding="5,5,10,5"
Width="90"
IsEnabled="{Binding Path=IsButtonEnabled}"
Click="EnableDisableButton_Click">
<Button.Content>
<StackPanel Orientation="Horizontal" Margin="-5,0,0,0">
<Border Margin="0,0,10,0" BorderBrush="Black" BorderThickness="1">
<Canvas Width="10"
Background="{Binding Path=IsEnabled, Converter={StaticResource boolToColorConverter}}">
</Canvas>
</Border>
<Image Source="img/power.png" Width="20" Margin="10,0,0,0"></Image>
</StackPanel>
</Button.Content>
</Button>
<StackPanel Visibility="{Binding Path=ErrorMessage, Converter={StaticResource errorVisibilityConverter}}">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Stretch">
<Button x:Name="ErrorCloseButton"
Content="❌"
Width="16"
Height="16"
FontSize="8"
Click="OnErrorCloseButtonClicked"></Button>
<TextBlock Text="Error" FontSize="16" Padding="4,0" FontWeight="Bold"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding Path=ErrorMessage}"
HorizontalAlignment="Left"
TextWrapping="Wrap"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- not found text -->
<TextBlock Margin="10" Text="No game controllers found">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding Items.Count}" Value="0">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock Opacity="0.3" HorizontalAlignment="Right">
<Hyperlink x:Name="nameLink" Click="nameLink_Click"
FontStyle="Normal" Foreground="Black"
TextDecorations="{x:Null}">GitHub</Hyperlink> - Aug 2018
</TextBlock>
</StackPanel>
</Window>