windows phone 通用应用程序中未选定枢轴的枢轴控件 header 图标
Pivot control header icon of un selected pivot in windows phone universal application
我的通用 windows phone 应用程序中有枢轴控件。像这样定义
<PivotItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0 0 10 0" Width="40" Source="/Assets/Images/cher.png" />
<TextBlock x:Uid="cherTextBlock" Grid.Column="1" Style="{StaticResource PivotHeadingStyle}" />
</Grid>
</PivotItem.Header>
当我在第一个轴心时,第二个轴心的文字变得乏味。但当然图像不会变得沉闷。我有相同的图像但效果暗淡,我希望在显示其他枢轴时显示该暗淡图像。
一种方法是我以编程方式制作它,并在图像未聚焦时更改图像源。但我想知道是否有可能在 xaml 或其他比我更好的方法中做到这一点?
以编程方式完成它
在初始化组件中添加了这段代码
//RechargeAccountPivot is name of my pivot control.
RechargeAccountPivot.SelectionChanged += RechargeAccountPivot_SelectionChanged;
这是 selectionChanged 事件代码。我在这里为所有图像控件命名并更改了它们的图标。
private void RechargeAccountPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RechargeAccountPivot.SelectedIndex == 0)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCard.png"));// new BitmapImage { UriSource = new Uri("//Assets/Images/BalanceTopUpIcons/rechargeCard.png") };
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else if (RechargeAccountPivot.SelectedIndex == 1)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
}
}
我的通用 windows phone 应用程序中有枢轴控件。像这样定义
<PivotItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0 0 10 0" Width="40" Source="/Assets/Images/cher.png" />
<TextBlock x:Uid="cherTextBlock" Grid.Column="1" Style="{StaticResource PivotHeadingStyle}" />
</Grid>
</PivotItem.Header>
当我在第一个轴心时,第二个轴心的文字变得乏味。但当然图像不会变得沉闷。我有相同的图像但效果暗淡,我希望在显示其他枢轴时显示该暗淡图像。
一种方法是我以编程方式制作它,并在图像未聚焦时更改图像源。但我想知道是否有可能在 xaml 或其他比我更好的方法中做到这一点?
以编程方式完成它
在初始化组件中添加了这段代码
//RechargeAccountPivot is name of my pivot control.
RechargeAccountPivot.SelectionChanged += RechargeAccountPivot_SelectionChanged;
这是 selectionChanged 事件代码。我在这里为所有图像控件命名并更改了它们的图标。
private void RechargeAccountPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RechargeAccountPivot.SelectedIndex == 0)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCard.png"));// new BitmapImage { UriSource = new Uri("//Assets/Images/BalanceTopUpIcons/rechargeCard.png") };
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else if (RechargeAccountPivot.SelectedIndex == 1)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
}
}