亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

來自 C# 代碼隱藏中的 xaml 等效項的自定義顏色

來自 C# 代碼隱藏中的 xaml 等效項的自定義顏色

C#
米琪卡哇伊 2023-07-09 09:52:07
我在 wpf 應用程序中有一個帶有網格的窗口。網格有一個十六進制背景值。我只想從代碼后面檢查該背景的值是否是我真正的意思。<Grid Background="#424242" Name="GridMain">在后面的代碼中我得到:SolidColorBrush a = new SolidColorBrush();var b = (SolidColorBrush)new BrushConverter().ConvertFrom("#424242");MainWindow mainWin = Application.Current.MainWindow as MainWindow;if (mainWin.GridMain.Background ==  b)     MDark.IsChecked = true;不得不提的是,MDark 是一個單選按鈕。而且這個條件永遠不會成立。我很感激你的幫助。:D
查看完整描述

1 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

您正在比較SolidColorBrush實例,它們顯然不一樣。而是比較實際的顏色值:


var c = (Color) ColorConverter.ConvertFromString ("#424242");

MainWindow mainWin = Application.Current.MainWindow as MainWindow;

if (((SolidColorBrush) mainWin.GridMain.Background).Color == c) 

{

    MDark.IsChecked = true;

}


查看完整回答
反對 回復 2023-07-09
  • 1 回答
  • 0 關注
  • 122 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號