Grid App 프로젝트 템플릿의 dataItems에 대한 데이터 템플릿은 StandardStyles.xaml에 있으며 "Standard250x250ItemTemplate"키로 참조됩니다.
아이디어가 항목의 내용에 따라 스타일을 변경하는 경우 한 가지 방법은 Binding.Converter, as shown here을 사용하여 해당 내용의 값을 원하는 스타일 또는 스타일 속성으로 변환하는 것입니다.
예를 들어, 항목 번호가 3보다 작거나 같으면 기본 그리드 앱 템플리트의 항목을 녹색 배경으로하고 싶고 3보다 높으면 빨간색으로 만들려면 다음을 작성하십시오. 컨버터 클래스 (내 경우에는, 난 그냥 단지 GroupedItemsPage 부분 클래스 전에 GroupedItemsPage.xaml.cs에 클래스를 추가) : 클래스가 정의
// Custom class implements the IValueConverter interface.
public class StyleConverter : IValueConverter
{
#region IValueConverter Members
// Define the Convert method to change a title ending with > 3
// to a red background, otherwise, green.
public object Convert(object value, Type targetType,
object parameter, string language)
{
// The value parameter is the data from the source object.
string title = (string)value;
int lastNum = (int.Parse(title.Substring(title.Length - 1)));
if (lastNum > 3)
{
return "Red";
}
else
{
return "Green";
}
}
// ConvertBack is not implemented for a OneWay binding.
public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
되면, 원하는 변환 방법과 함께, 내가 추가 내 App.xaml 파일에 인스턴스가 있으므로 StandardStyles.xaml의 항목 템플릿에서 사용할 수 있습니다.
<!-- Application-specific resources -->
<local:StyleConverter x:Key="StyleConverter"/>
는 StandardStyles.xaml에서, 나는 나의 컨버터 클래스, 항목의 제목 속성에서 결합 그래서 같은 Standard250x250ItemTemplate의 사본을 만들어 :
<DataTemplate x:Key="Standard250x250ItemTemplate_Convert">
<Grid HorizontalAlignment="Left" Width="250" Height="250">
<Border Background="{Binding Title,
Converter={StaticResource StyleConverter}}">
</Border>
<StackPanel VerticalAlignment="Bottom"
Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}" Height="60" Margin="15,0,15,0"/>
<TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/>
</StackPanel>
</Grid>
</DataTemplate>
하여 국경 요소의 결합 인 키 조각 타이틀에 배경 속성, 변환기 = {StaticResource StyleConverter}, 항목 템플릿을 변환기까지 연결합니다. Background 속성을 바인딩하는 것 외에도 항목 템플리트의 원래 버전에서 중첩 된 Image 요소를 제거했습니다.
마지막으로, GroupedItemsPage.xaml에, 내 사용자 정의 버전으로 항목 템플릿을 변경 :이 작업이 일단
<!-- Horizontal scrolling grid used in most view states -->
<GridView
x:Name="itemGridView"
...
Padding="116,137,40,46"
ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemTemplate="{StaticResource Standard250x250ItemTemplate_Convert}"
...
ItemClick="ItemView_ItemClick">
, 나는 여기에 프로젝트를 실행 수있는 것은 내가 볼 수있는 작업은 다음과 같습니다
희망이 도움이됩니다.
Windows 스토어 응용 프로그램 개발에 대한 자세한 내용은 Generation App에 등록하십시오.
지금 시점에서 방금 실험하고 있습니까? 아니면 스타일이 다른 주어진 항목의 기초로 사용할 계획이라는 특정 기준을 알고 계십니까? – devhammer