[WPF] 시티 캐스케이드(XmlDataProvider)
21997 단어 Provider
public class RegionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var name = value as string;
var filter = parameter as string;
if (string.IsNullOrEmpty(name) && filter != "country")
{
return null;
}
var provider = new XmlDataProvider();
provider.Source = new Uri("Resources/Region.xml", UriKind.Relative);
if (filter == "country")
{
provider.XPath = "/region/country/@name";
}
else if (filter == "province")
{
provider.XPath = string.Format("/region/country[@name='{0}']/province/@name", name);
}
else if (filter == "city")
{
provider.XPath = string.Format("/region/country/province[@name='{0}']/city/@name", name);
}
else if (filter == "town")
{
provider.XPath = string.Format("/region/country/province/city[@name='{0}']/town/@name", name);
}
return provider;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
다음에 어떻게 묶는지 볼게요.
<converters:RegionConverter x:Key="region"/>
<ComboBox Grid.Column="0" x:Name="country"
DataContext="{Binding Converter={StaticResource region}, ConverterParameter=country}"
SelectedValue="{Binding DataContext.CurrEditorItem.Country,UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource AncestorType={x:Type mui:ModernWindow}}}"
ItemsSource="{Binding}"
Width="85" Style="{StaticResource CommonComboBoxStyle}" />
<ComboBox Grid.Column="2" x:Name="province"
DataContext="{Binding SelectedValue, ElementName=country, Converter={StaticResource region}, ConverterParameter=province}"
SelectedValue="{Binding DataContext.CurrEditorItem.Province,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource AncestorType={x:Type mui:ModernWindow}}}"
ItemsSource="{Binding}"
Width="85" Style="{StaticResource CommonComboBoxStyle}" />
<ComboBox Grid.Column="4" x:Name="city"
DataContext="{Binding SelectedValue, ElementName=province, Converter={StaticResource region}, ConverterParameter=city}"
SelectedValue="{Binding DataContext.CurrEditorItem.City,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource AncestorType={x:Type mui:ModernWindow}}}"
ItemsSource="{Binding}"
Width="85" Style="{StaticResource CommonComboBoxStyle}" />
<ComboBox Grid.Column="6" x:Name="town"
DataContext="{Binding SelectedValue, ElementName=city, Converter={StaticResource region}, ConverterParameter=town}"
SelectedValue="{Binding DataContext.CurrEditorItem.Area,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource AncestorType={x:Type mui:ModernWindow}}}"
ItemsSource="{Binding}" Text="{Binding Area,UpdateSourceTrigger=PropertyChanged}"
Width="85" Style="{StaticResource CommonComboBoxStyle}" />
<TextBlock Grid.Column="0" Text=" " Tag="{Binding SelectedValue, ElementName=country}"
Style="{StaticResource TipTextBlock}"/>
<TextBlock Grid.Column="2" Text=" " Tag="{Binding SelectedValue, ElementName=province}"
Style="{StaticResource TipTextBlock}"/>
<TextBlock Grid.Column="4" Text=" / " Tag="{Binding SelectedValue, ElementName=city}"
Style="{StaticResource TipTextBlock}"/>
<TextBlock Grid.Column="6" Text=" / " Tag="{Binding SelectedValue, ElementName=town}"
Style="{StaticResource TipTextBlock}"/>
TextBlock은 ComboBox 위에 놓습니다. TextBlock 스타일은 다음과 같습니다.
<Style x:Key="TipTextBlock" TargetType="{x:Type TextBlock}">
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="12,0,0,0"/>
<Setter Property="Opacity" Value="0"/>
<Style.Triggers>
<Trigger Property="Tag" Value="{x:Null}">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
WPF에 열거된 응용 프로그램:
<ComboBox x:Name="cbbDataType" ItemsSource="{Binding Source={StaticResource InfoDetailTypeItems}}"
SelectedItem="{Binding CurrEditorItem.DataType, ValidatesOnDataErrors=True}"
ItemTemplate="{StaticResource InfoDetailTypeDataTemplate}"
Grid.Row="2" Grid.Column="1"
Style="{StaticResource EditorComboBoxStyle}" />
<x:Array x:Key="InfoDetailTypeItems" Type="{x:Type adservice:ShowDataType}">
<adservice:ShowDataType>Image</adservice:ShowDataType>
<adservice:ShowDataType>Video</adservice:ShowDataType>
<adservice:ShowDataType>ThreeDModel</adservice:ShowDataType>
</x:Array>
public ObservableCollection<Employee> userList = new ObservableCollection<Employee>();
public MainWindow()
{
InitializeComponent();
this.List.ItemsSource = userList;
ThreadPool.QueueUserWorkItem((m) =>
{
string myfiles = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var query = from pathname in Directory.GetFiles(myfiles) select new { pathtest = pathname };
foreach (var item in query)
{
this.Dispatcher.BeginInvoke(new Action(() =>
{
userList.Add(new Employee { Name = item.pathtest });
}));
Thread.Sleep(100);
}
});
}
private IList<CategoryTreeDataModel> GenerateTree(IEnumerable<CategoryTreeDataModel> list)
{
IDictionary<int, IList<CategoryTreeDataModel>> childDict = new Dictionary<int, IList<CategoryTreeDataModel>>();
//
foreach (var item in list)
{
if (!childDict.ContainsKey(item.ParentId))
childDict.Add(item.ParentId, new List<CategoryTreeDataModel>());
var tempList = childDict[item.ParentId];
tempList.Add(item);
}
if (!childDict.ContainsKey(0)) return null;
// TreeModel
foreach (var itemList in childDict.Values)
{
foreach (var item in itemList)
{
var parentId = item.CategoryId;
item.Children = childDict.ContainsKey(parentId) ? childDict[parentId] : null;
}
}
return GenerateListTree(childDict[0], 0, childDict).ToList();
}
/// <summary>
///
/// </summary>
/// <param name="list"> </param>
/// <param name="level"> </param>
/// <param name="childDict"> </param>
private IEnumerable<CategoryTreeDataModel> GenerateListTree(IEnumerable<CategoryTreeDataModel> list, int level, IDictionary<int, IList<CategoryTreeDataModel>> childDict)
{
if (list == null) yield break;
foreach (var item in list)
{
yield return item;
if (!childDict.ContainsKey(item.CategoryId)) continue;
foreach (var childItem in GenerateListTree(childDict[item.CategoryId], level + 1, childDict))
{
yield return childItem;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ASP. NET 에서. NET Data Provider for Oracle 의 연결 구멍우리 시스템 에 이 문제 가 있 습 니 다. 인터넷 에서 마이크로소프트 패 치 프로그램 을 찾 을 수 없습니다. 누가 마이크로소프트 의 수정 프로그램 을 다운로드 하고 링크 다운 로드 를 제공 하 는 지 모 르 겠 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.