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

发布于 2024-10-24 06:00:37 字数 979 浏览 1 评论 0原文

我正在使用一个自动完成框,它绑定到代码隐藏中的列表。我想要的是,当列表中没有商品时,自动完成框应显示一条消息“不存在卖家”。

以下是 xaml 代码

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

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

Code-behind

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃梦幻 2024-10-31 06:00:37

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

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

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文