我创建了一个相当简单的UserControl
,它由TextBox
和ComboBox
组成。访问自定义控件中多个控件的文本和内容
<StackPanel Orientation="Horizontal">
<MyNamespace:MultiBox Style="{StaticResource PhoneBoxStyle}" BoxType="Phone" Grid.Column="0" Grid.Row="0" Name="phoneNumber" Margin="50,0,5,5" MinWidth="250"/>
<ComboBox Grid.Column="1" Grid.Row="0" Height="{Binding ElementName=phoneNumber, Path=Height}" MinWidth="100" Name="callResultsSelection" ItemsSource="{Binding Source={StaticResource callResults}}" Margin="0,0,5,5"/>
</StackPanel>
我需要能够然后使用一个按钮的按下导出这些的.Text
& .SelectedItem
值。我尝试使用下面的属性,但它似乎不工作。它确实通过控件的IntelliSense公开.Text
属性,但它不会按照预期将任何内容复制到剪贴板。
原始(和所需的)的方法:
public string Text
{
get { return phoneNumber.Text + " - " + callResultsSelection.SelectedItem + "\r\n"; }
set { value = phoneNumber.Text + " - " + callResultsSelection.SelectedItem + "\r\n"; }
}
回退的方法:
public string Text
{
get { return phoneNumber.Text; }
set { value = phoneNumber.Text; }
}
public string ComboBoxSelection
{
get { return callResultsSelection.SelectedItem.ToString(); }
set { value = callResultsSelection.SelectedItem.ToString(); }
}
我使用的控制迭代如下。这些部分还有很多,但这是唯一相关的部分。
foreach (object o in ccChildren.GetChildren(tool, 3))
{
if (o.GetType() == typeof(CallTemplate))
{
CallTemplate template = (CallTemplate)o;
if (template.Text != null)
{
textBuffer += template.Text;
}
else
{
textBuffer = "";
}
tempString += textBuffer;
textBuffer = "";
}
}
通过使用断点,我知道,它确实达到在if
块的决策点,但即使VS识别CallTemplate
对象,它不匹配。任何人都看到了问题?
编辑:我知道问题不在于迭代方法(ccChildren.GetChildren)。我使用这个与其他众多控件(文本框,组合框,单选按钮,复选框),它工作得很好。该领域唯一可能成为问题的是CallTemplate
类型。
在属性.Text @集{}你应该使用值,而不是分配它! – mrbm 2012-03-02 17:36:19
else { textBuffer =“”; } 似乎是错的? – mrbm 2012-03-02 17:41:16
我把值切换到等号的另一边,没有效果。至于textBuffer =“”,迭代的控件是一系列标签和文本框。在if块之前,该标签被添加到textBuffer中。但是,如果标签引用的控件为空,则标签不需要添加到tempString中,因此没有空行。 – 2012-03-02 17:49:04