IConverter C#,wpf ,checkbox.Checked -
xaml code
<treeview.resources> <local:booltovisibleorhidden x:key="booltovisconverter" collapse="true"/> </treeview.resources> <treeviewitem header="first child" name="_firstchild" visibility="{binding path=visibleoncheck, mode=oneway, notifyontargetupdated=true, converter={staticresource booltovisconverter}}" /> <checkbox name="_checkboxvisible" ischecked="{binding path= visibleoncheck, mode=twoway}" content="show" checked="checkbox />
checkbox checked
private void checkbox(object sender, routedeventargs e) { if (messagebox.show("", "", messageboxbutton.yesno) == system.windows.forms.dialogresult.yes) { visibleoncheck = true; } else { visibleoncheck = false; } }
model code
private bool __visible; public bool visibleoncheck { { return _ visible; } set { _visible = value; onpropertychanged("visibleoncheck "); } } public class booltovisibleorhidden : ivalueconverter { #region constructors public booltovisibleorhidden() { } #endregion #region propertie collapse public bool collapse { get; set; } public bool reverse { get; set; } #endregion #region ivalueconverter members public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { bool bvalue = (bool)value; if (bvalue != reverse) { return visibility.visible; } else { if (collapse) return visibility.collapsed; else return visibility.hidden; } } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { visibility visibility = (visibility) value; if (visibility == visibility.visible) return !reverse; else return reverse; } #endregion }
i want ,treeview item header should visible when messagebox .yes clicked, here visible’s messagebox , treeviewitem same time without clicking messagebox.yes, can 1 please.
you have twoway binding on checkbox visibleoncheck
, if check checkbox
going toggle visibility
on treeviewitem
.
if want handle visibleoncheck
in checked event handler based on dialogresult
have remove twoway binding or binding altogether.
<checkbox name="_checkboxvisible" content="show" checked="checkbox />
i suggest using wpf
messagebox
on winforms
one, seems bit odd drag in framework messagebox
.
private void checkbox(object sender, routedeventargs e) { visibleoncheck = messagebox.show("","", messageboxbutton.yesno) == messageboxresult.yes; }
edit
since problem due both controls binding visibleoncheck
bind treeviewitem
visibility
directly checkbox
in xaml
<textblock text="treeviewitem" visibility="{binding ischecked, elementname=chkbx, converter={staticresource booleantovisibilityconverter}}" /> <checkbox x:name="chkbx" content="checkbox" checked="checked" />
and in event set ischecked
based on dialog result
private void checked(object sender, routedeventargs e) { (sender checkbox).ischecked = messagebox.show("","", messageboxbutton.yesno) == messageboxresult.yes; }
Comments
Post a Comment