I’ve created a fairly simple UserControl consisting of a TextBox and 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>
I need to be able to then export the .Text & .SelectedItem values of those with the press of a single button. I tried using a property like below, but it doesn’t seem to work. It does expose a .Text property through IntelliSense for the control, but it doesn’t copy anything to the clipboard as intended.
Original (and desired) approach:
public string Text
{
get { return phoneNumber.Text + " - " + callResultsSelection.SelectedItem + "\r\n"; }
set { value = phoneNumber.Text + " - " + callResultsSelection.SelectedItem + "\r\n"; }
}
Fallback approach:
public string Text
{
get { return phoneNumber.Text; }
set { value = phoneNumber.Text; }
}
public string ComboBoxSelection
{
get { return callResultsSelection.SelectedItem.ToString(); }
set { value = callResultsSelection.SelectedItem.ToString(); }
}
The control iteration I’m using is as follows. There are a lot more of these sections, but this is the only relevant one.
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 = "";
}
}
By using breakpoints, I do know that it does reach the decision point in the if block, but even though VS recognizes the CallTemplate object, it doesn’t match it. Anyone see the problem?
Edit: I do know that the problem is not with the iteration method (ccChildren.GetChildren). I am using this with a multitude of other controls (textbox, combobox, radio button, checkbox) and it works perfectly fine. The only thing in that area that could be an issue is the CallTemplate type.
So this would be one of those moments of sheer stupidity. My only problem was that I hadn’t added the GroupBox containing the UserControl to the array of GroupBoxes to iterate through. Thanks for the helpful replies though…