【发布时间】:2016-04-19 21:26:54
【问题描述】:
所以,我做了一个非常简单的尝试,尝试从我拥有的类的属性中进行数据绑定,但是,无论出于何种原因,代码实际上做了任何事情。它没有抛出任何错误,但某些东西一定不能正常工作。我目前只是在测试它是否会像我想要的那样运行,在这种情况下,它将把矩形的不透明度设置为零。这是似乎不想正确响应的数据模板的 xaml:
<HubSection x:Name="China" Width="440" Height="460" Background="#FF343434" Header="China" IsHeaderInteractive="True" Tapped="{x:Bind HubSectionTapped}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,0,0,0">
<DataTemplate x:DataType="data:MainPageView">
<Grid Height="460" Width="410" VerticalAlignment="Bottom" x:Name="ChinaBackground">
<Image Source="Assets/chinaFlag.bmp" x:Name="ChinaFlag"/>
<Rectangle x:Name="ChinaSelected_Rect" Width="410" Height="30" VerticalAlignment="Bottom" Fill="BlueViolet" Opacity="{x:Bind Opacity1}"/>
</Grid>
</DataTemplate>
</HubSection>
下面是代码:
public MainPageView TheMainPageView;
public MainPage()
{
this.InitializeComponent();
timer = new DispatcherTimer();
timer.Tick += Timer_DyanmicResize;
timer.Tick += Timer_SelectionIndicator;
timer.Start();
TheMainPageView = new MainPageView ();
}
最后,这里是引用的 MainPageView 类:
public class MainPageView
{
public int Opacity1 {get; set;}
public int Opacity2 {get;set;}
public int Opacity3 { get; set; }
public MainPageView()
{
this.Opacity1 = 0;
this.Opacity2 = 0;
this.Opacity3 = 0;
}
}
在 XAML 中,我包含了 xmlns:data="using:TestApp.Models"(models 是 MainPageView 所在的文件夹)。正如我所说,它没有抛出错误,但它也没有做任何事情,所以我有点不知道从哪里开始解决这个问题,因为没有任何错误可以追溯。提前感谢你们提供的任何帮助
【问题讨论】:
标签: c# xaml data-binding uwp win-universal-app