gpt4 book ai didi

c# - 将项目添加到 Azure 简易表时,未将 UWP 对象引用设置为对象的实例

转载 作者:行者123 更新时间:2023-11-30 23:07:50 24 4
gpt4 key购买 nike

我有一个弹出窗口,它接收用户的输入,然后将其发送到模型,然后将其发布到 azure 的简单表。当我构建项目时,一切都运行良好,直到我点击提交按钮,然后应用程序崩溃,并且我得到空异常对象引用未设置为对象的实例。

用于输入的 XAML:

<Popup x:Name="ppup" IsOpen="False" IsLightDismissEnabled="True"  
Width="320" HorizontalAlignment="Left">
<Popup.ChildTransitions>
<TransitionCollection>
<!--<EdgeUIThemeTransition Edge="Left" />-->
<PaneThemeTransition Edge="Left" />
</TransitionCollection>
</Popup.ChildTransitions>
<Grid Width="380" Height="{Binding ElementName=flyoutPane, Path=Height}" Background="{ThemeResource FlyoutBackgroundThemeBrush}" >
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,10,10,10" >
<TextBlock Name="NameText" Text="Enter Name:"/>
<TextBox Name="NameBox" Width="200" Height="50"/>
<TextBlock Name="SetsText" Text="Enter Sets:"/>
<TextBox Name="SetsBox" Width="200" Height="50"/>
<TextBlock Name="TimeText" Text="Enter Time to complete:"/>
<TextBox Name="TimeBox" Width="200" Height="50"/>
<Button Name="SubmitBtn" Height="30" Width="100" Content="Submit" Click="SubmitBtn_Click"/>
</StackPanel>
</Grid>
</Popup>

C# 用于处理输入并将其传递给模型:

CombatTableView ctv = new CombatTableView();

private async void SubmitBtn_Click(object sender, RoutedEventArgs e)
{
DrillItem drillItem = new DrillItem();
String Name = NameBox.Text;
int Sets = Int32.Parse(SetsBox.Text);
int Time = Int32.Parse(TimeBox.Text);
await ctv.combatDrillsTable.AddDrill(drillItem, Name, Sets, Time, parameters);
ppup.IsOpen = false;
var dialog = new MessageDialog("Your message here");
await dialog.ShowAsync();
}

查看模型:

 class CombatTableView
{
public CombatDrillsTable combatDrillsTable { get; set; }

public CombatTableView()
{
this.combatDrillsTable = new CombatDrillsTable();
}
}

与数据库交互的模型:

public async Task AddDrill(DrillItem drillItem, String n, int s, int t, string sty)
{
drillItem.Name = n;
drillItem.Sets = s;
drillItem.SetTime = t;
drillItem.Style = sty;

await App.MobileService.GetTable<DrillItem>().InsertAsync(drillItem);
drills.Add(drillItem);
}

最佳答案

就我而言,问题是由于复选框意外绑定(bind)到事件而不是属性造成的:

<CheckBox x:Name="chkIsActive" Checked="{Binding IsActive}" />

而不是

<CheckBox x:Name="chkIsActive" IsChecked="{Binding IsActive}" />

关于c# - 将项目添加到 Azure 简易表时,未将 UWP 对象引用设置为对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46930752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com