无法将值设置/绑定到文本框

时间:2014-05-22 01:17:37

标签: c# windows xaml

我正在尝试在Windows 8.1 c#xaml app中将默认值设置为textbox / bind数据。我正在尝试使用.Text或.DataContent的textbox属性,但它无法正常工作。谁能帮我回答原因?

c#中的代码

    private void setDefault(object sender, RoutedEventArgs e)
    {

        pan.Text = company.account.panno;
        Vat.Text =company.account.vat.ToString();
        year.Text = company.account.buyingAccount.year.ToString();
        mon.Text = company.account.buyingAccount.mon.ToString();
    }

xaml中的代码

       <GridView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"     UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Center">
                        <GridView.RenderTransform>
                            <CompositeTransform SkewX="1.583" TranslateX="1.465"/>
                        </GridView.RenderTransform>
                        <TextBlock HorizontalAlignment="Center" Grid.Row="1" FontSize="25" FontStyle="Italic" RenderTransformOrigin="0.355,-0.056" Width="95" >Settings</TextBlock>
                    </GridView>
                    <GridView Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Height="60" Margin="0,20,0,17" Width="50">
                        <TextBlock FontSize="20" FontWeight="Medium" VerticalAlignment="Center">Pan</TextBlock>
                    </GridView>
                    <GridView Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" >
                       <TextBox x:Name="pan" Width="294" Text="{Binding}"/>
                    </GridView>
                    <GridView Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <Button Content="Change" Click="changePan"/>
                    </GridView>
                    <GridView Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" >
                        <TextBlock FontSize="20" FontWeight="Medium">Year</TextBlock>
                    </GridView>
                    <GridView Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <TextBox x:Name="year" Width="100" Text="{Binding}" />
                    </GridView>
                    <GridView Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <Button Content="Change" Click="changeYear"/>
                    </GridView>
                    <GridView Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" >
                        <TextBlock FontSize="20" FontWeight="Medium" VerticalAlignment="Center">Month</TextBlock>
                    </GridView>
                    <GridView Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" >
                        <TextBox x:Name="mon" Width="100" Text="{Binding}" />

                    </GridView>
                    <GridView Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" >
                        <Button Content="Change" Click="changeMon"/>
                    </GridView>
                    <GridView Grid.Row="4" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <TextBlock FontSize="20" FontWeight="Medium" VerticalAlignment="Center">VAT</TextBlock>
                    </GridView>
                    <GridView Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <TextBox x:Name="Vat" Width="100" Text="{Binding}"/>
                    </GridView>
                    <GridView Grid.Row="4" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <Button Content="Change" Click="changeVat"/>
                    </GridView>

                    <GridView Grid.Row="5" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" >
                        <TextBlock FontSize="20" FontWeight="Medium" VerticalAlignment="Center" >Previous Month Tax Due</TextBlock>
                    </GridView>
                    <GridView Grid.Row="5" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <TextBox x:Name="Pre" Width="100" Text="{Binding}"/>
                    </GridView>
                    <GridView Grid.Row="5" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <Button Content="Change" Click="changePre"/>
                    </GridView>
                    <GridView Grid.Row="6" Grid.Column="0" HorizontalAlignment="Center"  Grid.ColumnSpan="2">
                        <StackPanel Orientation="Horizontal">
                            <Button Click="goToBuying">
                                Buying Account
                            </Button>
                            <Button Click="goToSelling">
                                Selling Account
                            </Button>
                        </StackPanel>
                    </GridView>

0 个答案:

没有答案