티스토리 뷰

WPF

contentpresenter checkbox casting error

NicSub 2018. 12. 18. 11:55
728x90
반응형

wpf System.Windows.controls.contentpresenter checkbox casting error


       FrameworkElement element = this.dataGrid1.Columns[4].GetCellContent(dataGrid1.Items[Row_num]);
                    object chk = FindVisualChild<CheckBox>(element);
                    if (chk != null)
                    {
                        CheckBox use2 = chk as CheckBox;
                        if (use2.IsChecked ?? false)
                        {
                            MessageBox.Show("update1");
                        }
                        else
                        {
                            MessageBox.Show("update2");
                        }

                    }




     private childItem FindVisualChild<childItem>(DependencyObject obj)
           where childItem : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(obj, i);
                if (child != null && child is childItem)
                    return (childItem)child;
                else
                {
                    childItem childOfChild = FindVisualChild<childItem>(child);
                    if (childOfChild != null)
                        return childOfChild;
                }
            }
            return null;
        }

반응형

'WPF' 카테고리의 다른 글

비동기 소켓 서버  (0) 2019.02.26
IP 할당(IPAddress)  (0) 2019.02.25
DataGrid 선택된 셀 좌표  (0) 2018.12.11
SqlDataReader & SqlDataAdapter  (0) 2018.12.05
item_list  (126) 2018.12.05
댓글