關(guān)于WPF使用MultiConverter控制Button狀態(tài)的詳細(xì)介紹_.Net教程
推薦:基于自定義Unity生存期模型PerCallContextLifeTimeManager的問(wèn)題本篇文章小編將為大家介紹,基于自定義Unity生存期模型PerCallContextLifeTimeManager的問(wèn)題。需要的朋友參考下
需求描述
1.按鈕的狀態(tài)需要根據(jù)多個(gè)數(shù)據(jù)源的內(nèi)容作出不同的組合判斷
2.每個(gè)數(shù)據(jù)源的判斷規(guī)則可定制
注:以下功能感覺(jué)只是簡(jiǎn)單粗暴的實(shí)現(xiàn),如果您了解更優(yōu)雅的解決方案,煩請(qǐng)告訴我下,感謝先!
按鈕XAML
<Button Name="btnOK"
Grid.Column="2"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Command="{Binding Path=OKCommand}"
Content="{DynamicResource Common_Button_OK}"
IsDefault="True"
Style="{DynamicResource ButtonStyle}">
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource InvalidMultiValidationRuleToBooleanMultiConverter}"
ConverterParameter="objectnull|greaterthanzerointeger|greaterthanzerointeger|greaterthanzerointeger">
<Binding ElementName="comboBoxFilter"
Mode="OneWay"
Path="SelectedItem" />
<Binding ElementName="textBoxFrameRate"
Mode="OneWay"
Path="Text" />
<Binding ElementName="textBoxSizeWidth"
Mode="OneWay"
Path="Text" />
<Binding ElementName="textBoxSizeHeight"
Mode="OneWay"
Path="Text" />
</MultiBinding>
</Button.IsEnabled>
</Button>
MultiConverter判斷
public class InvalidMultiValidationRuleToBooleanMultiConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string[] paramlist = ((string)parameter).Split('|');
if (paramlist == null || paramlist.Length <= 0)
{
throw new ArgumentNullException("parameter");
}
int length = paramlist.Length;
IList<bool> boollist = new List<bool>();
for (int i = 0; i < paramlist.Length; i++)
{
switch (paramlist[i].ToLowerInvariant())
{
case "checknameexisted":
boollist.Add(ValidationRuleHelper.Validate<InvalidCheckNameExistedValidationRule>(values[i]));
break;
case "directoryandfileexist":
boollist.Add(ValidationRuleHelper.Validate<InvalidDirectoryAndFileExistValidationRule>(values[i]));
break;
case "greaterthanzerointeger":
boollist.Add(ValidationRuleHelper.Validate<InvalidGreaterThanZeroIntegerValidationRule>(values[i]));
break;
case "numericnull":
boollist.Add(ValidationRuleHelper.Validate<InvalidNumericNullValidationRule>(values[i]));
break;
case "stringlength":
boollist.Add(ValidationRuleHelper.Validate<InvalidStringLengthValidationRule>(values[i]));
break;
case "stringnullorempty":
boollist.Add(ValidationRuleHelper.Validate<InvalidStringNullOrEmptyValidationRule>(values[i]));
break;
case "ipaddress":
boollist.Add(ValidationRuleHelper.Validate<InvalidIPAddressValidationRule>(values[i]));
break;
case "objectnull":
default:
boollist.Add(ValidationRuleHelper.Validate<InvalidObjectNullValidationRule>(values[i]));
break;
}
}
bool result = boollist[0];
for (int i = 1; i < boollist.Count; i++)
{
result = result & boollist[i];
}
return result;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
#endregion
}
分享:asp.net C#實(shí)現(xiàn)下載文件的六種方法實(shí)例asp.net C#實(shí)現(xiàn)下載文件的六種方法實(shí)例,需要的朋友可以參考一下
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶(hù)端IP常見(jiàn)代碼存在的偽造IP問(wèn)題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- Web里URL空格的轉(zhuǎn)換方法
- 基于.NET平臺(tái)的分層架構(gòu)實(shí)戰(zhàn)(一) 綜述
- 淺談ASP.NET的PHP執(zhí)行速度
- 如何實(shí)現(xiàn)vs.net控件updatePanel無(wú)刷新
- .Net教程之HTTP狀態(tài)碼200,301,302
- .Net應(yīng)用:制作ASP腳本組件實(shí)現(xiàn)重啟服務(wù)器
- [JS.IntelliSense]VS2007(Orcas) So Cool
- GridView中動(dòng)態(tài)設(shè)置CommandField是否可用或可見(jiàn)的小例子
- ASP.NET筆記之頁(yè)面跳轉(zhuǎn)、調(diào)試、form表單、viewstate、cookie的使用說(shuō)明
- 探索 ASP.NET Futures
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索關(guān)于WPF使用MultiConverter控制Button狀態(tài)的詳細(xì)介紹
- 教程說(shuō)明:
.Net教程-關(guān)于WPF使用MultiConverter控制Button狀態(tài)的詳細(xì)介紹。