Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在XAML中将国家列表作为combobox的自动完成_Wpf_Powershell_Xaml - Fatal编程技术网

Wpf 如何在XAML中将国家列表作为combobox的自动完成

Wpf 如何在XAML中将国家列表作为combobox的自动完成,wpf,powershell,xaml,Wpf,Powershell,Xaml,我正在做一个使用XAML和PowerShell的项目,这是我第一个使用XAML的项目。我有一个表单,用户输入一个国家名称,组合框应该自动完成国家名称。我无法做到这一点 我正在使用的Combobox的XAML代码如下 CountryList-我从csv文件中选择它,CountryList是标题列。这对我不起作用。请问有什么帮助吗? 我正在使用PowerShell脚本 <ComboBox Name="country" HorizontalAlignment="Left" Height="32"

我正在做一个使用XAML和PowerShell的项目,这是我第一个使用XAML的项目。我有一个表单,用户输入一个国家名称,组合框应该自动完成国家名称。我无法做到这一点

我正在使用的Combobox的XAML代码如下

CountryList-我从csv文件中选择它,CountryList是标题列。这对我不起作用。请问有什么帮助吗? 我正在使用PowerShell脚本

<ComboBox Name="country" HorizontalAlignment="Left" Height="32" 
Margin="194,227,0,0" VerticalAlignment="Top" Width="330" FontSize="16" 
VerticalContentAlignment="Center" IsEditable="True" 
IsTextSearchEnabled="True" TextSearch.TextPath="countryList" ItemsSource=" 
{Binding countryList}"/>

使用您给我的,我删除了以下部分:

  • TextSearch.TextPath=“countryList”
    来自XAML中的组合框
  • 已从CSV导入中删除
    输出字符串
这就是我正在使用的:

Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration

[xml]$xaml = @"
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="GreenLake FlexCapacity" 
    Height="500" Width="850">
    <Grid>
        <TextBox Name="ASM" HorizontalAlignment="Left" Height="32" Margin="194,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="email" HorizontalAlignment="Left" Height="32" Margin="194,104,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="company" HorizontalAlignment="Left" Height="32" Margin="194,165,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <ComboBox Name="country" HorizontalAlignment="Left" Height="32" Margin="194,227,0,0" VerticalAlignment="Top" Width="330" FontSize="16" VerticalContentAlignment="Center" IsEditable="True" IsTextSearchEnabled="True"/>
        <TextBlock Name="ASM_name" HorizontalAlignment="Left" Height="26" Margin="102,54,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="ASM_email" HorizontalAlignment="Left" Height="26" Margin="102,110,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Email"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="company_name" HorizontalAlignment="Left" Height="26" Margin="66,171,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="128" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="Company Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="country_name" HorizontalAlignment="Left" Height="26" Margin="124,226,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="65" FontSize="16" RenderTransformOrigin="0.864,0.918" Text="Country"/>
        <Button Name="create" Content="Create ID" HorizontalAlignment="Left" Height="34" Margin="194,281,0,0" VerticalAlignment="Top" Width="164" FontSize="16"/>
        <Button Name="cancel" Content="Cancel" HorizontalAlignment="Left" Height="34" Margin="381,281,0,0" VerticalAlignment="Top" Width="143" FontSize="16"/>
        <TextBlock Name="Cust_ID" HorizontalAlignment="Left" Height="48" Margin="159,348,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="389" FontSize="18" FontWeight="Bold"/>
    </Grid>
</Window>
"@

$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$window=[Windows.Markup.XamlReader]::Load($reader)

$country = $window.FindName("country")

$countryList = Import-Csv -Path C:\Users\harwoodm\Desktop\Country-codes.csv | Select-Object -ExpandProperty "Country Name"

$country.ItemsSource = $countryList

$window.ShowDialog() | Out-Null
添加类型-程序集名称表示框架、System.Drawing、System.Windows.Forms、WindowsForms集成
[xml]$xaml=@”
"@
$reader=(新对象System.Xml.XmlNodeReader$xaml)
$window=[Windows.Markup.XamlReader]::加载($reader)
$country=$window.FindName(“国家”)
$countryList=导入Csv-路径C:\Users\harwoodm\Desktop\Country-codes.Csv |选择对象-ExpandProperty“国家名称”
$country.ItemsSource=$countryList
$window.ShowDialog()| Out Null
这是正在运行的表单的屏幕截图:


使用您给我的,我删除了以下部分:

  • TextSearch.TextPath=“countryList”
    来自XAML中的组合框
  • 已从CSV导入中删除
    输出字符串
这就是我正在使用的:

Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration

[xml]$xaml = @"
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="GreenLake FlexCapacity" 
    Height="500" Width="850">
    <Grid>
        <TextBox Name="ASM" HorizontalAlignment="Left" Height="32" Margin="194,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="email" HorizontalAlignment="Left" Height="32" Margin="194,104,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="company" HorizontalAlignment="Left" Height="32" Margin="194,165,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <ComboBox Name="country" HorizontalAlignment="Left" Height="32" Margin="194,227,0,0" VerticalAlignment="Top" Width="330" FontSize="16" VerticalContentAlignment="Center" IsEditable="True" IsTextSearchEnabled="True"/>
        <TextBlock Name="ASM_name" HorizontalAlignment="Left" Height="26" Margin="102,54,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="ASM_email" HorizontalAlignment="Left" Height="26" Margin="102,110,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Email"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="company_name" HorizontalAlignment="Left" Height="26" Margin="66,171,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="128" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="Company Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="country_name" HorizontalAlignment="Left" Height="26" Margin="124,226,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="65" FontSize="16" RenderTransformOrigin="0.864,0.918" Text="Country"/>
        <Button Name="create" Content="Create ID" HorizontalAlignment="Left" Height="34" Margin="194,281,0,0" VerticalAlignment="Top" Width="164" FontSize="16"/>
        <Button Name="cancel" Content="Cancel" HorizontalAlignment="Left" Height="34" Margin="381,281,0,0" VerticalAlignment="Top" Width="143" FontSize="16"/>
        <TextBlock Name="Cust_ID" HorizontalAlignment="Left" Height="48" Margin="159,348,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="389" FontSize="18" FontWeight="Bold"/>
    </Grid>
</Window>
"@

$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$window=[Windows.Markup.XamlReader]::Load($reader)

$country = $window.FindName("country")

$countryList = Import-Csv -Path C:\Users\harwoodm\Desktop\Country-codes.csv | Select-Object -ExpandProperty "Country Name"

$country.ItemsSource = $countryList

$window.ShowDialog() | Out-Null
添加类型-程序集名称表示框架、System.Drawing、System.Windows.Forms、WindowsForms集成
[xml]$xaml=@”
"@
$reader=(新对象System.Xml.XmlNodeReader$xaml)
$window=[Windows.Markup.XamlReader]::加载($reader)
$country=$window.FindName(“国家”)
$countryList=导入Csv-路径C:\Users\harwoodm\Desktop\Country-codes.Csv |选择对象-ExpandProperty“国家名称”
$country.ItemsSource=$countryList
$window.ShowDialog()| Out Null
这是正在运行的表单的屏幕截图:



您的itemsource看起来像什么?我们无法判断它的格式或处理是否正确。
countryList=Import Csv-Path“C:\Country codes.Csv”|选择Object-ExpandProperty'Country Name'| Out String
,我在XAML
ItemsSource=“{Binding countryList}中调用它
在PowerShell中,我的呼叫方式如下所示。(不确定这是否正确)
$country.ItemSource=$countryList
我会从XAML中删除绑定,并尝试在代码中仅使用
$country.ItemSource=$countryList
,我也尝试过,但没有任何区别。它仍然显示相同的dropbox作为一个字符,而不是一个名称。不知道为什么。你能用尽可能多的代码和细节更新你的问题以重现问题吗?这样我可以自己测试它,并让你知道我是否遇到了相同的问题。你能分享你的CSV或用它的外观和一些示例数据更新你的问题吗?你的itemsource看起来像什么?我们不能我不知道它的格式或处理是否正确。
$countryList=Import Csv-Path“C:\Country codes.Csv”|选择Object-ExpandProperty'Country Name'| Out String
,我在XAML
ItemsSource=“{Binding countryList}中调用它
在PowerShell中,我的呼叫方式如下。(不确定这是否正确)
$country.ItemsSource=$countryList
我将从XAML中删除绑定,并尝试在代码中仅使用
$country.ItemSource=$countryList
,我也尝试过,但这没有任何区别。它仍然显示与单个字符相同的dropbox,而不是名称。不知道为什么。你能用尽可能多的代码和细节来更新你的问题吗?这样我可以自己测试,如果我遇到同样的问题,我会告诉你。您是否也可以分享您的CSV或更新您的问题,以了解它的外观和一些示例数据?它工作得非常好,谢谢。我们可以让自动完成也在下拉列表中显示匹配项吗?就像您键入United时一样,在下拉列表中应该显示3个列表项-仅限阿拉伯联合酋长国、英国、美国?有可能吗?@Hari如果我的回答回答了你的问题,请向上投票,并标记它有答案:)我不确定,我从来没有做过这样的事情。由于这是一个单独的问题/请求,因此应将其放入一个新的问题中,以避免将重点转移到这个问题上:)完成。任何参考链接,你可以提供第二个问题将是有益的。再次感谢。@Hari你能不能也投票支持我对这个问题的回答?这对我和未来的访客都有帮助:)我做不到,这是我在这里的第一个问题,所以,它非常有效,谢谢。我们可以让自动完成也在下拉列表中显示匹配项吗?就像您键入United时一样,在下拉列表中应该显示3个列表项-仅限阿拉伯联合酋长国、英国、美国?有可能吗?@Hari如果我的回答回答了你的问题,请向上投票,并标记它有答案:)我不确定,我从来没有做过这样的事情。由于这是一个单独的问题/请求,因此应将其放入一个新的问题中,以避免将重点转移到这个问题上:)完成。任何参考链接,你可以提供第二个问题将是有益的。再次感谢。@Hari你能不能也投票支持我对这个问题的回答?信息技术
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration

[xml]$xaml = @"
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="GreenLake FlexCapacity" 
    Height="500" Width="850">
    <Grid>
        <TextBox Name="ASM" HorizontalAlignment="Left" Height="32" Margin="194,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="email" HorizontalAlignment="Left" Height="32" Margin="194,104,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <TextBox Name="company" HorizontalAlignment="Left" Height="32" Margin="194,165,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="330" FontSize="16"/>
        <ComboBox Name="country" HorizontalAlignment="Left" Height="32" Margin="194,227,0,0" VerticalAlignment="Top" Width="330" FontSize="16" VerticalContentAlignment="Center" IsEditable="True" IsTextSearchEnabled="True"/>
        <TextBlock Name="ASM_name" HorizontalAlignment="Left" Height="26" Margin="102,54,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="ASM_email" HorizontalAlignment="Left" Height="26" Margin="102,110,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="92" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="ASM Email"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="company_name" HorizontalAlignment="Left" Height="26" Margin="66,171,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="128" FontSize="16" RenderTransformOrigin="0.864,0.918"><Run Text="Company Name"/><LineBreak/><Run/></TextBlock>
        <TextBlock Name="country_name" HorizontalAlignment="Left" Height="26" Margin="124,226,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="65" FontSize="16" RenderTransformOrigin="0.864,0.918" Text="Country"/>
        <Button Name="create" Content="Create ID" HorizontalAlignment="Left" Height="34" Margin="194,281,0,0" VerticalAlignment="Top" Width="164" FontSize="16"/>
        <Button Name="cancel" Content="Cancel" HorizontalAlignment="Left" Height="34" Margin="381,281,0,0" VerticalAlignment="Top" Width="143" FontSize="16"/>
        <TextBlock Name="Cust_ID" HorizontalAlignment="Left" Height="48" Margin="159,348,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="389" FontSize="18" FontWeight="Bold"/>
    </Grid>
</Window>
"@

$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$window=[Windows.Markup.XamlReader]::Load($reader)

$country = $window.FindName("country")

$countryList = Import-Csv -Path C:\Users\harwoodm\Desktop\Country-codes.csv | Select-Object -ExpandProperty "Country Name"

$country.ItemsSource = $countryList

$window.ShowDialog() | Out-Null