I have a button with a custom template. Do you have any idea how I can rename the content in the button with a double click. This is what I have, but from code I cannot access b1.textBox to set the visibility to visible.
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
开发者_C百科 <Grid>
<Ellipse x:Name="outerCircle" Fill="Red" Height="50" Width="50"/>
<Ellipse x:Name="innerCircle" Fill="White" RenderTransformOrigin=".5,.5">
<Ellipse.RenderTransform>
<ScaleTransform ScaleX=".9" ScaleY=".9"/>
</Ellipse.RenderTransform>
</Ellipse>
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBox x:Name="textBox" Visibility="Collapsed"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
void button1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//MessageBox.Show(e.Source.ToString());
Button b1 = (Button)e.Source;
// b1.textBox doesn't get displayed here.
}
what about
b1.Template.FindName("textBox",b1) as TextBox
?
Why not just add this to the style?
<EventSetter Event="MouseDoubleClick" Handler="HandleDoubleClick" />
Then in code behind:
protected void HandleDoubleClick(object sender, MouseButtonEventArgs e)
{
Button b1 = (Button)sender;
}
精彩评论