我有以下XAML代碼,其中我將一些數據綁定到列表視圖。另外,我有非常重要的RecipientConverter
,它允許我轉換我的TextBlock。但是,這是問題。該TextBlock必須按照下面TextBlock中提供的格式(Binding Path = Sum)進行轉換。 所以,這是我的問題,是否可以將「Sum」TextBlock作爲ConverterParameter發送到RecipientConverter
?我知道MultipleBinding
,但這隻適用於WPF,並不適用於UWP。也許這是一種與DependencyProperty
一起實現它的方式,但我很確定。使用ConverterParameter的UWP多重綁定
NOTE: 「收件人」TextBlock和「Sum」TextBlock是我從服務器獲得的動態值。
<ListView x:Name="HistoryList" Padding="10" IsItemClickEnabled="True" Visibility="Collapsed" ItemsSource="{Binding Source={StaticResource TransactionsCVS}}" ItemsPanel="{StaticResource ResourceKey=ItemsPanelTemplate}" ItemClick="HistoryList_ItemClick">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:TransactionGroupInfo">
<TextBlock FontWeight="Medium" FontSize="16" Foreground="#999999" Text="{Binding Path=Key}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:Transaction">
<Grid Height="60" Margin="0,5,0,5" Background="White" CornerRadius="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Background="{Binding Path=VendorAccentColor}" CornerRadius="5,0,0,5" />
<StackPanel VerticalAlignment="Center" Margin="10,0,0,0" Grid.Column="1" Orientation="Vertical">
<TextBlock Text="{Binding Path=VendorName}" FontSize="16" Foreground="#999999" />
<TextBlock Text="{Binding Path=Recipient, Converter={StaticResource RecipientConverter}}" FontSize="16" Foreground="#999999" />
</StackPanel>
<TextBlock Grid.Column="2" Text="{Binding Path=Sum, Converter={StaticResource SumConverter}}" VerticalAlignment="Center" Canvas.ZIndex="2" Margin="0,0,10,0" FontSize="18" FontWeight="Bold" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
這裏是我的變換器的C#代碼
public object Convert(object value, Type targetType, object parameter, string language)
{
string recipient = (string)value;
// Here is a way I want it to be
string sum = (string)parameter;
if (HalykWallet_v03.Model.AppSettings.GetAppLang() == "ru")
{
if (sum.Contains("-"))
return "На " + recipient;
else
return "От " + recipient;
}
else
{
char[] array = sum.ToCharArray();
if (sum.Contains("-"))
{
switch (array.Last())
{
case '0':
case '1':
case '2':
recipient += recipient + "-ден";
break;
case '3':
case '4':
case '5':
recipient += recipient + "-тен";
break;
case '6':
recipient += recipient + "-дан";
break;
case '7':
case '8':
recipient += recipient + "-ден";
break;
case '9':
recipient += recipient + "-дан";
break;
default:
break;
}
}
else
{
switch (array.Last())
{
case '0':
case '1':
case '2':
recipient += recipient + "-ге";
break;
case '3':
case '4':
case '5':
recipient += recipient + "-ке";
break;
case '6':
recipient += recipient + "-ға";
break;
case '7':
case '8':
recipient += recipient + "-ден";
break;
case '9':
recipient += recipient + "-ға";
break;
}
}
return recipient;
}
}
不,不幸的是,它不起作用,在轉換器內參數等於NULL。我在某處閱讀了ConverterParameter中不支持Binding的地方。這就是問題所在...... –
您可以使用Cimbalino windows手機工具包模擬多重綁定行爲:https://www.pedrolamas.com/2013/05/17/cimbalino-windows-phone-toolkit-multibindingbehavior/ –
歡迎您: ), –