問題:所以我的應用程式有 2 個選項,加載和更新。當我想更新時,我也想復制內容(如名稱/UID),但我不能。在更新期間,我設定了“isEnabled=False”(通過將其系結到變數)它不會讓我復制內容。
我嘗試做“isReadOnly=True”(洗掉“isEnabled”屬性),它允許我復制,但 DropDown 仍在作業,這將允許我或任何人更改某些值(如性別、UID)以在期間更改更新。
目標:我希望能夠復制組合框的內容但不允許任何人更改其值。
或者
有沒有辦法禁用下拉功能,以便“isReadOnly=True”可以解決問題。
uj5u.com熱心網友回復:
如果isReadOnly=True正在做您想做的事情,那么我將只使用轉換器來禁用下拉串列。
在MainWindow.xaml:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1">
<Window.Resources>
<local:CBMaxDropDownHeightConverter x:Key="CBMaxDropDownHeightConverter" />
</Window.Resources>
<Grid>
<ComboBox MaxDropDownHeight="{Binding RelativeSource={RelativeSource Self}, Path=IsReadOnly, Converter={StaticResource CBMaxDropDownHeightConverter}}" />
</Grid>
</Window>
然后在 CBMaxDropDownHeightConverter.cs
using System;
using System.Windows.Data;
namespace WpfApp1
{
public class CBMaxDropDownHeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (System.Convert.ToBoolean(value) == true)
{
return "0";
}
return "Auto";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/357645.html
下一篇:無法讓執行緒和影片旋轉作業
