我正在以编程方式创建按钮并将它们添加到堆栈面板,以便每次用户导航到页面时按钮都会更改.我正在尝试做类似这样的事情,当我点击创建的按钮时,它会抓住按钮的标签并转到正确的页面.但是,我无法使用RoutedEventHandler访问按钮元素.这是代码:
foreach (item in list)
{
Button newBtn = new Button();
newBtn.Content = "Button Text";
newBtn.Tag = item.Tag;
newBtn.Name = item.Name;
newBtn.Click += new RoutedEventHandler(newBtn_Click);
}
private void newBtn_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/DetailPage.xaml?selectedItem=" + sender.Tag, UriKind.Relative));
}
Run Code Online (Sandbox Code Playgroud) 我已按照 Windows 安装的建议将 git 配置为 autocrlf=true 。但是,当我运行flutter pub get我的pubspeck.lock文件时,不断获取 lf 作为行结尾。有没有办法配置 flutter 以使其尊重 clrf 设置?
# git status
On branch develop
Your branch is up to date with 'origin/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: pubspec.lock
no changes added to commit (use "git add" and/or "git commit -a")
# git diff pubspec.lock
warning: LF will be …Run Code Online (Sandbox Code Playgroud) 我一直在使用我的应用程序使用Azure移动服务没有太多问题,但是今天当我尝试从服务中提取时出现此错误:
Exception = System.Data.SqlClient.SqlException(0x80131904):无法打开登录请求的数据库"master".登录失败.用户'JVlSvKwDpdLogin_ ***** ' 登录失败.
我以前从来没有遇到过这个问题,我只是用这样的代码连接到我的移动服务:
public static MobileServiceClient MobileService = new MobileServiceClient(
"https://<webservicename>.azure-mobile.net/",
"<YOUR-API-KEY-HERE>"
);
Run Code Online (Sandbox Code Playgroud)
在发生此错误之前,我从未提供用户名或密码.我已经看到了一些解决方案,他们为数据库创建了一个用户,但我现在不想创建一个用户,因为我们还在测试中,而现在我宁愿能够使用该服务.这是移动服务的问题,还是数据库的问题?
UPDATE
正如下面Matt的回答所示,我在Azure门户中找到了MS_ConnectionString.然后,我连接到Azure SQL服务器上的"主"数据库,并搜索上面的登录信息.我将密码更改为使用连接字符串中找到的密码
ALTER LOGIN <login> WITH password='<password-found-in-connection-string>';
Run Code Online (Sandbox Code Playgroud)
但是现在我收到了这个错误:
Exception = System.Data.Entity.Core.ProviderIncompatibleException:访问数据库时出错.这通常意味着与数据库的连接失败.检查连接字符串是否正确,以及是否使用了相应的DbContext构造函数来指定它或在应用程序的配置文件中找到它.有关DbContext和连接的信息,请参阅http://go.microsoft.com/fwlink/?LinkId=386386.有关失败的详细信息,请参阅内部异常.---> System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串.---> System.Data.SqlClient.SqlException:用户'JVlSvKwDpdLogin_ ******* ' 登录失败.
我没有使用连接字符串或AzureMobileService项目的web.config文件进行任何更改.
web.config中:
<connectionStrings>
<add name="MS_TableConnectionString" connectionString="Data Source= (localdb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-CoverageTool.AzureMobileService-20140910083006.mdf;Initial Catalog=aspnet-CoverageTool.AzureMobileService-20140910083006;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
MobileContext:
private const string connectionStringName = "Name=MS_TableConnectionString";
public MobileServiceContext()
: base(connectionStringName)
{
}
Run Code Online (Sandbox Code Playgroud)
连接字符串
数据源= ***** .database.windows.net;初始目录= sbpconsulting_db;用户ID = *******Login_sbpconsulting;密码=************** ;异步加工= TRUE; TrustServerCertificate = FALSE;
c# sql-server azure azure-mobile-services azure-sql-database
我正在尝试在文本下方创建多个按钮,并在运行时将它们添加到代码中的Stackpanel中。我基于数据列表创建按钮。这是我的代码:
XAML
<StackPanel x:Name="MainSP" />
Run Code Online (Sandbox Code Playgroud)
C#
foreach (item in ItemList)
{
Button newBtn = new Button();
Image buttonImage = new Image();
buttonImage.Width = 100;
buttonImage.Height = 100;
buttonImage.Stretch = Systems.Windows.Media.Stretch.Uniform;
buttonImage.Source = new BitmapImage(pokemon.ImageURI);
newBtn.Tag = item.Id;
newBtn.Name = String.Format("{0}Button", item.Name);
newBtn.Click += new RoutedEventHandler(newBtn_Click);
FamilyStackPanel.Children.Add(newBtn);
}
Run Code Online (Sandbox Code Playgroud)
我知道这是笨拙的编程。我真的很想在XAML中设置ControlTemplate,然后在代码中创建按钮时重用它。这是XAML:
<ControlTemplate x:Key="ButtomTemplate" TargetType="Button">
<Grid Height="108" Width="Auto" Margin = "6,6">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Width = "54" Height="54" Stretch="UniformToFill" Grid.Row="0">
<Image.Source>
<BitmapImage UriSource="{Binding ImageUri}" CreateOptions="BackgroundCreation"/>
</Image.Source>
</Image>
<TextBlock Text="{Binding Name}" …Run Code Online (Sandbox Code Playgroud) 每当对象被序列化时,我想在一个字段前加上一个字符串值。有没有办法用杰克逊做到这一点?我想在类名前加上 id 前缀。
public class CarClass {
public Long id;
public String name;
......
}
Run Code Online (Sandbox Code Playgroud)
示例类将是...
CarClass car1 = new CarClass (1,"First car");
Run Code Online (Sandbox Code Playgroud)
我希望它像这样被 serilized:
{
"id": "carClass-1",
"name": "First car"
}
Run Code Online (Sandbox Code Playgroud)