C# 当不存在任何项目时,“自动完成”框将弹出默认消息
我正在使用一个自动完成框,它绑定到代码隐藏中的列表。我想要的是,当列表中没有项目时,自动完成框应该显示一条消息“不存在卖家” 下面是xaml代码C# 当不存在任何项目时,“自动完成”框将弹出默认消息,c#,wpf,xaml,autocomplete,C#,Wpf,Xaml,Autocomplete,我正在使用一个自动完成框,它绑定到代码隐藏中的列表。我想要的是,当列表中没有项目时,自动完成框应该显示一条消息“不存在卖家” 下面是xaml代码 <rm:AutoCompleteBox Name="sellerText" Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" HorizontalAlignment="Left" Width="170" Margin="110,40,0,0" > <rm:Auto
<rm:AutoCompleteBox Name="sellerText" Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" HorizontalAlignment="Left" Width="170" Margin="110,40,0,0" >
<rm:AutoCompleteBox.SelectedItem>
<Binding Source="{StaticResource insertTransaction}" Mode="TwoWay" UpdateSourceTrigger="Explicit" Path="Seller">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</rm:AutoCompleteBox.SelectedItem>
</rm:AutoCompleteBox>
代码隐藏
public NewRecord()
{
InitializeComponent();
List<string> ledgerList = new List<string>();
ledgerList = DAL_LedgerNameList.LoadLedgers();
sellerText.ItemsSource = ledgerList;
}
public NewRecord()
{
初始化组件();
List-ledgerList=新列表();
ledgerList=DAL_LedgerNameList.LoadLedgers();
sellerText.ItemsSource=ledgerList;
}
您可以将此逻辑添加到代码隐藏中
public NewRecord()
{
InitializeComponent();
List<string> ledgerList = new List<string>();
ledgerList = DAL_LedgerNameList.LoadLedgers();
if (ledgerList.Length==0)
{
sellerText.ItemsSource = new string() {"No Sellers Exist"}
}
else
{
sellerText.ItemsSource = ledgerList;
}
}
public NewRecord()
{
初始化组件();
List-ledgerList=新列表();
ledgerList=DAL_LedgerNameList.LoadLedgers();
如果(账本列表长度==0)
{
sellerText.ItemsSource=新字符串(){“不存在卖家”}
}
其他的
{
sellerText.ItemsSource=ledgerList;
}
}
非常感谢您的回复,但这会创建另一个带有“不存在卖家”字符串的列表,当我按“n”时,该字符串会弹出。我想要的是,如果没有匹配项,那么应该弹出一条默认消息,或者当没有项目时。我在其他论坛上得到了一个更好的答案,dat是在文本框中添加一个水印。无论如何,谢谢你的时间伙伴