0
我得到這個錯誤:的DataTemplate和WrapPanel知名度
Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.
使用XAML代碼:
<WrapPanel Orientation="Horizontal" Grid.Row="0" >
<WrapPanel.Visibility>
<Binding Path="setVisible" Converter="{StaticResource BooleanToVisibilityConverter}" ConverterParameter="{Binding setVisible}"/>
</WrapPanel.Visibility>
//textblocks goes here
</WrapPanel>
和類:
public class dataTemplate_xItem
{
(...)
public bool setVisible { get; set; }
public sealed class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var flag = false;
if (value is bool)
{
flag = (bool)value;
}
else if (value is bool?)
{
var nullable = (bool?)value;
flag = nullable.GetValueOrDefault();
}
if (parameter != null)
{
if (bool.Parse((string)parameter))
{
flag = !flag;
}
}
if (flag)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var back = ((value is Visibility) && (((Visibility)value) == Visibility.Visible));
if (parameter != null)
{
if ((bool)parameter)
{
back = !back;
}
}
return back;
}
}
}
而且我加入項目之前ListView,檢查
if(myValue != 0)
newItem.setVisible = true;
else
newItem.setVisible = false;
任何想法出了什麼問題? :)
我看到至少有一件事是錯誤的,勢必'ConverterParameter'。有關詳細信息,請參閱[此答案](http://stackoverflow.com/a/15309844/1021555)。 – icebat