![](/img/trans.png)
[英]MultiBinding and IMultiValueConverter Convert() called only once
[英]MultiBinding and IMultiValueConverter.Can't get working
我目前正在嘗試編寫代碼,其主要內容是將三個傳入變量與用戶控件綁定。 按照計划,最后一個應該根據 IMultiValueConverter 中實現的邏輯交換顏色。
<UserControl
x:Class="TestApp_WPF.User_Controls.Axis"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converters="clr-namespace:TestApp_WPF.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestApp_WPF.User_Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="UserControl_Axis"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<UserControl.Resources>
<Converters:WyeDeltaMultiConverter x:Key="WDMultiConverter" />
</UserControl.Resources>
<Grid>
<Ellipse
Width="17"
Height="17"
Stroke="Black">
<Ellipse.Fill>
<MultiBinding Converter="{StaticResource WDMultiConverter}">
<Binding Path="Prty_L_feedback" />
<Binding Path="Prty_D_feedback" />
<Binding Path="Prty_Axis_failed" />
</MultiBinding
</Ellipse.Fill>
</Ellipse>
</Grid>
</UserControl>
WDMultiConverter:
class WyeDeltaMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
bool? state_0 = values[0] as bool?;
bool? state_1 = values[1] as bool?;
bool? state_2 = values[2] as bool?;
if (state_0 == null && state_1 == null && state_2 == null)
return Brushes.OrangeRed;
if (state_0 == true && state_1 == null && state_2 == null)
return Brushes.Azure;
if (state_0 == true && state_1 == true && state_2 == null)
return Brushes.LawnGreen;
if (state_0 == true && state_1 == true && state_2 == null)
return Brushes.OrangeRed;
return Brushes.WhiteSmoke;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
請有任何建議!
關於此資源有用性的謠言顯然被誇大了。 今天的例子正好證明了這一點。 這里有幾個人很快就失去了興趣。 也許在過去,我根據長期存在的帖子判斷,該資源被真正的代碼大師訪問過。 不幸的是,這幾天不是。 另外值得注意的是,資源具有非常不友好的界面和評分系統。
一個由我自己創建的答案:它在每個 Binding 中都缺少ElementName 。
<Binding ElementName="UserControl_Axis" Path="Prty_L_feedback" />
<Binding ElementName="UserControl_Axis" Path="Prty_D_feedback" />
<Binding ElementName="UserControl_Axis" Path="Prty_Axis_failed" />
當然,在使 XAML 代碼正常工作后,我對位於轉換器中的所謂布爾邏輯進行了一些更改。
就這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.