2011-03-19 36 views
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; 
    } 

回答

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

以及感谢背后的答复,但该用“No Sellers Exist”字符串创建另一个列表,当我按“n”时弹出该列表。我想要的是,如果没有匹配,那么默认消息应该弹出或没有项目时。 – 2011-03-22 07:42:23

+0

那么我在其他论坛上得到了更好的答案,并且dat是为文本框添加水印。不管怎样,谢谢你的时间伴侣 – 2011-04-23 07:36:33