Autocomplete box pops a default message when no item exist
I am using an autocomplete box which is binded to a list in code-behind. What i want is that when there is no item in the list, the autocomplete box should show a message "no seller exist".
Following is the xaml-code
<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.Se开发者_StackOverflow社区lectedItem>
</rm:AutoCompleteBox>
Code-behind
public NewRecord()
{
InitializeComponent();
List<string> ledgerList = new List<string>();
ledgerList = DAL_LedgerNameList.LoadLedgers();
sellerText.ItemsSource = ledgerList;
}
You could just add this logic in your code behind
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;
}
}
精彩评论