我是C#,Windows應用商店的新手,我正在努力解決問題。我想實現一些模板控件,它由一個帶有進度環和文本的彈出框組成。TemplateBinding:成員<>無法識別或無法訪問
在Template類(CustomProgressRing.cs)中,我希望能夠操作封閉的彈出窗口和它的屬性。 我通過將Text道具設置爲TempalteBinding來成功實現TextBlock,因此在該類中我可以訪問TextBlock的Text屬性。 我想將TemplateBinding應用於彈出的ISOPEN支柱,但我得到的錯誤: The member "IsOpen" is not recognized or is not accessible
下面是XAML:
<Style TargetType="local:CustomProgressRingPopup">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomProgressRingPopup">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Popup x:Name="ProgressRingPopup" x:Uid="LoggingInWaitingPopup" IsOpen="{TemplateBinding IsOpen}">
<Grid x:Name="gdChild" Width="Auto" Height="Auto" Background="#969696" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="LoginProgressRingText" Height="Auto" Width="Auto" FontSize="20" Margin="20" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Text="{TemplateBinding Text}"/>
</Grid>
</Popup>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
這裏是CustomProgressRing.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using System.Diagnostics;
// The Templated Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234235
namespace QSTLibrary.WIN8.Tools
{
public sealed class CustomProgressRingPopup : Control
{
public CustomProgressRingPopup()
{
this.DefaultStyleKey = typeof(CustomProgressRingPopup);
}
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
// Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
"Text",
typeof(string),
typeof(CustomProgressRingPopup),
new PropertyMetadata("Void", new PropertyChangedCallback(OnTextChanged)));
private void ProgressRingPopup_Opened(object sender, object e)
{
Debug.WriteLine("Popup opened");
}
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CustomProgressRingPopup instance = d as CustomProgressRingPopup;
if (instance != null)
{
string newValue = e.NewValue as string;
instance.Text = newValue;
//instance.IsOpen = true; - not working
}
}
}
}
爲什麼我不能將templateBinding設置爲Popup的IsOpen支柱?
你可以發佈CustomProgressRingPopup類的定義嗎? –
CustomProgressRingPopup定義了IsOpen依賴項屬性?它是派生Popup? – Nitin
@Moozhe - 我發佈了類定義 –