[英]Hold state of buttons dont work after binding
我有一個UWP應用程序,其中的按鈕保持狀態可以正常工作,直到我綁定(任何)按鈕可見性或保持狀態消失的可編輯狀態為止。 只有在綁定某些東西后我快速點擊超級按鈕,這些按鈕才起作用。 如果我切換到其他視圖,然后又回到原始視圖,則按鈕會再次神奇地起作用。 任何人都有什么想法可能導致這種情況嗎?
在xaml中為父級和按鈕添加了IsHoldingState =“ true”。
XAML代碼
<controls:RoundedButton Grid.Row="2" Style="{StaticResource SubmitButtonStyle}" Command="{Binding SubmitCommand}" VerticalAlignment="Bottom" Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter=false}" Margin="-16,-16,-32,-32" Width="384" Height="112" Opacity="0" Background="Transparent" />
<controls:RoundedButton Grid.Row="2" Style="{StaticResource SubmitButtonStyle}" Command="{Binding SubmitCommand}" VerticalAlignment="Bottom" Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter=false}">
cs代碼(其中綁定通過onpropertychanged更新)
private bool isNotEmpty;
public bool IsNotEmpty
{
get { return isNotEmpty; }
set { Set(() => IsNotEmpty, ref isNotEmpty, value); }
}
protected bool Set<T>(Expression<Func<T>> selectorExpression, ref T field, T value)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
RaisePropertyChanged(selectorExpression);
return true;
}
protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> selectorExpression)
{
var propertyName = GetPropertyName(selectorExpression);
OnPropertyChanged(propertyName);
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
問題可能出在您的ConverterParameter
,無法將ConverterParameter
直接分配給boolean
值,請嘗試以下操作:
<Page.Resources>
<x:Boolean x:Key="DefaultParameter">False</x:Boolean>
</Page.Resources>
...
<controls:RoundedButton Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter={StaticResource DefaultParameter}}">
最好的祝福。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.