我是使用 C# 进行编码的新手,我有使用 Laravel(php) 进行编码的背景。
我需要使用 CRUD 构建应用程序 (Windows 8.1)。但是在编辑中我遇到了问题,我需要知道如何将选定的项目传递到其他 xaml 文件中。
我需要将 MainPage 的选定项目传递给 Editar
MainPage.xaml.cs
namespace SQLiteDemo
{
///
/// An empty page that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainPage : Page
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("dados.sqlite");
public MainPage()
{
this.InitializeComponent();
conn.CreateTableAsync();
}
private async void Listar_Click(object sender, RoutedEventArgs e)
{
await Atualiza();
}
private async Task Atualiza()
{
var query = conn.Table();
listBox.ItemsSource = await query.ToListAsync();
}
private void Novo_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Novo));
}
private void Editar_Click(object sender, RoutedEventArgs e)
{
/*
var u = listBox.SelectedItem as User;
u.nome = "nome alterado";
await conn.UpdateAsync(u);
await Atualiza();
*/
listBox.SelectedItems.Add(listBox.SelectedItem as User);
var u = listBox.SelectedItem as User;
Frame.Navigate(typeof(SQLiteDemo.Editar), u);
}
}
}
Editar.xaml
<Grid HorizontalAlignment="Left" Height="520" Margin="55,115,0,0" VerticalAlignment="Top" Width="1155">
<TextBox x:Name="Nome" HorizontalAlignment="Left" Margin="70,60,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="40" Width="990" PlaceholderText="Nome"/>
<TextBox x:Name="Email" HorizontalAlignment="Left" Margin="70,140,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="40" Width="990" PlaceholderText="Email"/>
</Grid>
Editar.xaml.cs
namespace SQLiteDemo
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
///
public sealed partial class Editar : Page
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("dados.sqlite");
public Editar()
{
this.InitializeComponent();
conn.CreateTableAsync<User>();
}
private void SalvarEdit_Click(object sender, RoutedEventArgs e)
{
/*
var u = listBox.SelectedItem as User;
u.nome = Nome.Text;
u.email = Email.Text;
conn.UpdateAsync(u);
*/
}
private void Voltar_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(MainPage));
}
}
}
部分截图:
最佳答案
你向右传递参数,向左传递参数只是为了在导航后获取它。
将此函数添加到 Editar.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var user = e.Parameter as User;
Nome.Text = user.nome;
Email.Text = user.email;
}
关于c# - 将列表框的选定项目传递到 xaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44805302/
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只