110,571
社区成员
发帖
与我相关
我的任务
分享
<Grid>
<dxe:PopupBaseEdit HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" MaskType="DateTime" Mask="yyyy-MM">
<dxe:PopupBaseEdit.PopupContentTemplate>
<ControlTemplate>
<local:CustomDateNavigator x:Name="dateNavigator1" FocusedDate="{Binding Path=(dxe:BaseEdit.OwnerEdit).EditValue, Mode=TwoWay, RelativeSource={RelativeSource Self}}"/>
</ControlTemplate>
</dxe:PopupBaseEdit.PopupContentTemplate>
</dxe:PopupBaseEdit>
<Button Click="Button_Click"/>
</Grid>
private void Button_Click(object sender, RoutedEventArgs e)
{
Button bt = sender as Button;
string btnName = "";
List<DateNavigator> btnList = FindVisualChild<DateNavigator>((bt.Parent as Grid));
foreach (DateNavigator item in btnList)
{
btnName += string.IsNullOrEmpty(btnName) ? item.Name.ToString() : "," + item.Name.ToString();
}
MessageBox.Show(string.Format((bt.Parent as Grid).Name.ToString() + "共有{0}个,名称分别为{1}", btnList.Count, btnName));
}
List<T> FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
{
try
{
List<T> TList = new List<T> { };
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is T)
{
TList.Add((T)child);
}
else
{
List<T> childOfChildren = FindVisualChild<T>(child);
if (childOfChildren != null)
{
TList.AddRange(childOfChildren);
}
}
}
return TList;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
return null;
}
}
获取不了
<dxe:DateNavigator x:Class="FProject.CustomDateNavigator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
CalendarView="Years"
ShowTodayButton="False"
/>