当没有项目存在时,自动完成框会弹出默认消息

时间:2011-03-19 06:13:09

标签: c# wpf xaml autocomplete

我正在使用自动完成框,该框被绑定到代码隐藏中的列表。我想要的是,当列表中没有项目时,自动完成框应显示“无卖方存在”的消息。

以下是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.SelectedItem>
    </rm:AutoCompleteBox>

代码隐藏

public NewRecord()
    {
        InitializeComponent();
        List<string> ledgerList = new List<string>();
        ledgerList = DAL_LedgerNameList.LoadLedgers();
        sellerText.ItemsSource = ledgerList;
    }

1 个答案:

答案 0 :(得分:1)

您可以在代码中添加此逻辑

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;
    }
}