Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
using System.Windows.Controls;
using SDKSample;

namespace SDKSample {
namespace SDKSample
{

public partial class LogicalOverrideApp {
void AddLogicalElement(object sender, RoutedEventArgs e) {
Button mybutton = new Button();
mybutton.Content = "Happy birthday! " + System.DateTime.Now.TimeOfDay.ToString();
CustomElement.SetSingleChild(mybutton);
public partial class LogicalOverrideApp
{
void AddLogicalElement(object sender, RoutedEventArgs e)
{
Button myButton = new Button();
myButton.Content = "Happy birthday! " + System.DateTime.Now.TimeOfDay.ToString();
CustomElement.SetSingleChild(myButton);
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,40 @@

namespace SDKSample
{
//<SnippetSingletonPanel>
//<SnippetSingletonPanel>
public class SingletonPanel : StackPanel
{
//private UIElementCollection _children;
private FrameworkElement _child;

public SingletonPanel() {
public SingletonPanel()
{

}

public FrameworkElement SingleChild
{

get { return _child;}
get { return _child; }
set
{
if (value==null) {
RemoveLogicalChild(_child);
} else {
if (_child==null) {
_child = value;
} else {
// raise an exception?
MessageBox.Show("Needs to be a single element");
}
if (value == null)
{
RemoveLogicalChild(_child);
}
else
{
if (_child == null)
{
_child = value;
}
else
{
// raise an exception?
MessageBox.Show("Needs to be a single element");
}
}
}
}
}
public void SetSingleChild(object child)
{
Expand All @@ -54,20 +61,21 @@ public void SetSingleChild(object child)
}

public new void RemoveLogicalChild(object child)

{
_child = null;
this.Children.Clear();
}
protected override IEnumerator LogicalChildren
{
get {
// cheat, make a list with one member and return the enumerator
ArrayList _list = new ArrayList();
_list.Add(_child);
return (IEnumerator) _list.GetEnumerator();}
get
{
// cheat, make a list with one member and return the enumerator
ArrayList _list = new ArrayList();
_list.Add(_child);
return (IEnumerator)_list.GetEnumerator();
}
}
}
//</SnippetSingletonPanel>
//</SnippetSingletonPanel>
}