简体   繁体   中英

only one setter of the syle of a wpf datagrid is assigned. how to enable other setter?

i have added 2 setters to a style and assigned that style to a wpf datagridtemplatecolumn cell style. but one of them is assigned. another one is not assigned. any one know how to solve this?

 Style st = new Style();
 Setter sett2 = new Setter
 {
     Property = TextBox.BackgroundProperty,
     Value = Brushes.Yellow
 };
 Setter sett = new Setter
 {
     Property = TextBox.IsEnabledProperty,
     Value = false
 };
 st.Setters.Add(sett);
 st.Setters.Add(sett2);
 col.CellStyle = st;

Isenabled property is set false. but colur is still gray.

Cannot reproduce this (ie the background indeed becomes yellow).

If you explicitly set the background on the TextBox/TextBlock inside the template this style will not affect it due to dependency property value precedence . There could be other causes but there is not enough context to go by, for me at least.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM