0

在以下情况下我该怎么办?

我有一个简单的页面。在后面的代码中,我添加了 PhoneTextBox 控件以对数据进行一些过滤。但有时(经常)当我尝试写一些东西时,我看到里面的文字是透明的或折叠的或其他东西,所以我看不到它。即使选择此文本,我也看不到它。

// Generating of a PhoneTextBox    

SearchBox = new Microsoft.Phone.Controls.PhoneTextBox();
SearchBox.DataContext = searchBoxContext;
SearchBox.Name = string.Format("SearchBox_{0}", Guid.NewGuid());
SearchBox.Visibility = Visibility.Collapsed;

// Adding Phone text box in a Grid on the Page

RowDefinition rd = new RowDefinition();
rd.Height = GridLength.Auto;
PageDynamicGrid.RowDefinitions.Insert(0, rd);
Grid.SetRow(generator.SearchBox, 0);

foreach (FrameworkElement child in PageDynamicGrid.Children)
{
    Grid.SetRow(child, Grid.GetRow(child) + 1);
}

SearchBoxContext = (generator.SearchBox.DataContext as SearchButtonModel);
SearchBoxContext.SearchTextChanged += SearchBoxContext_SearchTextChanged;
generator.SearchBox.TextChanged += SearchBox_TextChanged;
generator.SearchBox.LostFocus += SearchBox_LostFocus;
generator.SearchBox.KeyUp += SearchBox_KeyUp;
generator.SearchBox.DataContext = null;
PageDynamicGrid.Children.Add(generator.SearchBox);
PageDynamicGrid.UpdateLayout();

和 page.xaml

<Grid x:Name="PageDynamicGrid" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="{Binding Title}"
                   Style="{StaticResource PhoneTextTitle1Style}" />
    </StackPanel>

    <ListBox Grid.Row="1" Margin="12,0"
             ItemsSource="{Binding PageDynamicContent, Mode=OneWay}"/>    
</Grid>

此页面的几乎所有内容(包括搜索框)都是动态创建的,但其他内容是一些按钮和链接,如果我有搜索框,我需要对其进行过滤。过滤器有效,但用户不喜欢搜索框中的折叠文本。所以它看起来像那样(并且标记前面没有空格)

在此处输入图像描述

4

1 回答 1

0

所以,我不知道为什么,但似乎问题出在行动的顺序上:

  1. 首先创建元素,更改网格列和行定义并在网格中添加元素。
  2. 更新网格的布局。
  3. 只有在所有这些操作之后,我们才能折叠 PhoneTextBox。

这个对我有用。

于 2013-09-26T07:08:41.067 回答