我想創建一個顏色選擇器,看起來像在Windows油墨: UWP:如何創建一個「四捨五入」拾色器
所以我創建了一個的GridView包含我的ItemTemplate :
<GridView x:Name="colorList2" HorizontalAlignment="Stretch" VerticalAlignment="Top"
IsItemClickEnabled="True"
ItemClick="colorList2_ItemClick"
SelectionMode="Single"
SelectionChanged="colorList2_SelectionChanged"
>
<GridView.ItemTemplate>
<DataTemplate>
<Grid RightTapped="Grid_RightTapped" Tapped="Grid_Tapped">
<Button Height="30" Width="30">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Ellipse Fill="{Binding Color}"/>
<ContentPresenter Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
在Grid_RightTapped和Grid_Tappent事件,我得到的點擊的顏色,我上色我的項目,我影響選定項目到GridView:
private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
Colors selectedColor = (sender as Grid).DataContext as Colors;
foreach (NodeViewModel node in diagram.Nodes as DiagramCollection<NodeViewModel>)
{
...
}
this.colorList2.SelectedItem = selectedColor;
}
}
這工作很好,但我想知道是否有一種方法來「定製」在GridView的選擇/懸停項目的模板? 這些都是正方形,我想用橢圓代替它們,就像在Windows Ink中一樣。
謝謝你們!這工作正常。 –