我有一个Javascript Windows 8应用程序.我正在使用C#编写WinRT组件DLL,以便与数据库连接.
对于所有函数,如OpenDB,ExecuteUpdate,ExecuteQuery(返回一行,返回一个列值),我已经完成了IASyncOperation并且非常成功.
但是为了逐个处理大结果集中的每一行,我需要将一个回调函数从javascript传递给C#WinRT组件DLL.所以代码就像,
My.WinRT.Component.Object.processEachRowASyc(query, arguments, function(row) {
/* Row specific processing */
}).then(function(result) {
/* Process after Entire Row processing is Complete */
});
Run Code Online (Sandbox Code Playgroud)
我写了这样的RT组件,
namespace mydb
{
public void delegate MyJSCallback(string msg);
public class Database {
public static IAsyncOperation<Database> OpenDB(string dbFile)
{
/* Open DB */
}
public IAsyncOperation<Database> ProcessEachRowASync(string sql,[ReadOnlyArray()] object[] arg, MyJSCallback myJSCallback)
{
return Task<Database>.Run(() =>
{
/* Query Processing */
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string toRet = "{\"Name\":\"Raju\", \"Age\":\"21\"}";
//Javascript …Run Code Online (Sandbox Code Playgroud) 在WinRT XAML中,我有一个ComboBox显示一些复杂项目.
是否可以声明并绑定两个不同的项模板:1)"普通"选定项目(ComboBox已关闭)和2)当用户想要选择另一个项目(ComboBox已打开)时弹出窗口中的列表?
我发现ItemTemplate两者兼而有之,但如果用户想要选择其他项目,我想显示具有略微不同模板的项目.
我有代码十六进制代码"FFB800",我需要在WinRT中转换为"颜色".
提前致谢.
页面中的一个文本框.我不能使用转换器(它没有工作),我不能使用CharacterCasing property
当我写文本时如何把大写我的文本框?
我使用Windows运行时为Windows 8.1开发,所以我在互联网上找不到很多帮助
我的代码:
KeyUp:
String str = "hello";
str = str.ToUpper();
str.Select(str.Count(), 0);
Run Code Online (Sandbox Code Playgroud)
KeyDown:
bool bModify = true;
Run Code Online (Sandbox Code Playgroud)
我的XAML代码:
<TextBox Name="Name" KeyUp="KeyUp" FontSize="20" Margin="15" Grid.Column="1" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" KeyDown="KeyDown"/>
Run Code Online (Sandbox Code Playgroud) 我创建了以下方法,可在已存在的SQLite表中添加一列
public async void AddColumnMyNewColumn()
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
await conn.ExecuteAsync("ALTER TABLE MyTable ADD COLUMN MyNewColumn bit DEFAULT 'False';");
}
Run Code Online (Sandbox Code Playgroud)
它在MyTable中创建一个新列MyNewColumn。
下次调用AddColumnMyNewColumn方法时,它将引发错误。
如何检查此列是否已创建?
我已经检查过这个和这个了,但是我不能将这些东西放在一起得到这样的东西。
public async void AddColumnMyNewColumn()
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(path);
bool columnExists;
//Check if column exists & set columnExists accordingly
if(!columnExists)
await conn.ExecuteAsync("ALTER TABLE MyTable ADD COLUMN MyNewColumn bit DEFAULT 'False';");
}
Run Code Online (Sandbox Code Playgroud) 我正在为TextBox构建一个用户控件,因为我希望它有一些特殊的行为.
该控件可用于多种上下文,包括作为按钮的弹出按钮.当它是弹出窗口时,我想在用户在编辑文本时按下Enter键时关闭弹出按钮.

为实现此目的,控件具有ParentButton依赖项属性,如果设置,则将按钮与弹出按钮存储,并且父页面的XAML在此情况下设置它.控件有一个KeyUp处理程序,用于检测Enter键,如果ParentButton设置了属性,则关闭其弹出按钮.
TextBoxUC.xaml
<UserControl
x:Class="TextBoxUCDemo.TextBoxUC"
...
xmlns:local="using:TextBoxUCDemo"
...>
<StackPanel Width="250">
<TextBox KeyUp="TextBox_KeyUp" Text="Hello" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
TextBoxUC.xaml.cs
public sealed partial class TextBoxUC : UserControl
{
public TextBoxUC() {
this.InitializeComponent();
}
internal static readonly DependencyProperty ParentButtonProperty =
DependencyProperty.Register("ParentButton", typeof(Button), typeof(TextBoxUC), new PropertyMetadata(null));
public Button ParentButton {
get { return ((Button)GetValue(ParentButtonProperty)); }
set { SetValue(ParentButtonProperty, value); }
}
private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e) {
switch (e.Key) {
case VirtualKey.Enter:
// (Do something with the Text...) …Run Code Online (Sandbox Code Playgroud) 我试图通过"HardCode"使用ContentDialog不在XAML页面中,我有很多TextBlocks要使用,所以我可能需要在ContentDialog中使用ScrollView或ListView,这是我的代码!
TextBlock txt = new TextBlock();
txt.Text = "TI Cajueiro Seco / Rua do Sol";
txt.FontSize = 25;
txt.Foreground = new SolidColorBrush(Colors.White);
txt.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
txt.VerticalAlignment = VerticalAlignment.Top;
txt.FontFamily = new FontFamily("/Fonts/MYRIADPRO-BOLD.OTF#Myriad Pro");
TextBlock txt2 = new TextBlock();
txt2.Text = "Rotas da Linha";
txt2.FontSize = 25;
txt2.Foreground = new SolidColorBrush(Colors.White);
txt2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
txt2.VerticalAlignment = VerticalAlignment.Bottom;
txt2.FontFamily = new FontFamily("/Fonts/Exo-Regular.ttf#Exo");
Grid grid = new Grid();
grid.Children.Add(txt2);
grid.Background = new SolidColorBrush(Colors.Red);
StackPanel stk = new StackPanel();
//stk.Children.Add(bar);
stk.Children.Add(txt);
stk.Children.Add(espaco);
stk.Children.Add(grid);
//stk.Children.Add(txt3); …Run Code Online (Sandbox Code Playgroud) 我在调用异步方法时遇到了一些麻烦.该方法在类中并加载文本文件.我想在应用程序启动时加载文本文件.但是,我无法从构造函数中调用异步方法.我在网上看过的大多数例子都经常从异步按钮事件中调用方法.
目前,我正在尝试从我的构造函数:
Task.Run(async () =>
{
this.categories = await GenerateCategories(numberOfCategories);
});
Run Code Online (Sandbox Code Playgroud)
尽管这样可行,但在调用此方法后,程序的其余部分仍会继续,并且使用"类别"执行的代码会导致崩溃(因为类别仍为空,因为任务尚未完成).
总而言之,从哪里以及如何最好地调用此方法?当用户按下按钮或任何东西时,我不希望它加载,我希望在执行任何更多代码之前填充"类别".
我正在使用C#并编写通用应用程序,因此加载文件必须是异步的.
我有一个ObservableCollection,我甚至先检查它以确保它有元素.然而,我仍然得到一个nullReferenceException(有时候,这从未出现过winrt 8.1版本的问题,我将其更改为UWP.)代码如下,它给出了错误,其中a.Url是:
if (sTumblrblog_gv_list.Count != 0)
{
if (tumblogconfig.ShowNSFWBlogs)
sTumblrGridView.ItemsSource = sTumblrblog_gv_list.OrderBy(a => a.Url);
else
sTumblrGridView.ItemsSource = sTumblrblog_gv_list.OrderBy(a => a.Url).Where(a => a.IsNsfw == false);
}
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Tumblr-FIA
StackTrace:
at tumblr_fia.MainPage.<>c.<updatestats>b__47_1(sTumblrblog_gv a)
at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
at System.Runtime.InteropServices.WindowsRuntime.EnumeratorToIteratorAdapter`1.MoveN
ext()
at System.Runtime.InteropServices.WindowsRuntime.EnumeratorToIteratorAdapter`1.get_HasCurrent()
InnerException:
Run Code Online (Sandbox Code Playgroud)
我理解这个错误我相信,但我检查sTumblrblog_gv_list不是空值.而我现在有一个尝试和捕获.有时我还会收到错误.
这是超级容易从去Platform::Guid^到Platform::String^与ToString()方法.有关详细信息,请参阅文档.
但是我们如何转换Platform::String^为Platform::Guid^?
编辑:
双方CLSIDFromString并IIDFromString就行了.请以接受的答案为例.还请#include <wrl\wrappers\corewrappers.h>.
我仍在掌握异步编程的过程中,并且对如何修改以下内容有些困惑:
基本虚拟方法:
public virtual async Task OnSuspendingAsync(object s, SuspendingEventArgs e)
{
// do some housekeeping actions upon suspending in the base class
await Task.Yield();
}
Run Code Online (Sandbox Code Playgroud)
覆盖方法:
public override Task OnSuspendingAsync(object s, SuspendingEventArgs e)
{
// do some housekeeping actions on exiting/suspending
return base.OnSuspendingAsync(s, e);
}
Run Code Online (Sandbox Code Playgroud)
问题:
现在,如果我在重写的方法中使用 awaitable(几乎不可避免),我需要通过添加关键字来更改public override Task为public override async Task,async如下面的真实示例所示。
public override async Task OnSuspendingAsync(object s, SuspendingEventArgs e)
{
try
{
// tidy up app temporary folder on exit
await ApplicationData.Current.ClearAsync(ApplicationDataLocality.Temporary); …Run Code Online (Sandbox Code Playgroud) 我试图绑定(在XAML中)到C++/CX中的List,我似乎没有任何列表.它们都去了哪里?任何类型的列表都可以...甚至是字典,堆栈,或......某事!或有C++改变了那么多,因为我最后一次使用它?
windows-runtime ×12
c# ×6
async-await ×2
c++-cx ×2
uwp ×2
winrt-xaml ×2
xaml ×2
asynchronous ×1
callback ×1
file-io ×1
javascript ×1
linq ×1
sqlite ×1
sqlite.net ×1
textbox ×1
uppercase ×1
visual-c++ ×1
wpf ×1