小编Dav*_*nes的帖子

文档库中的UWP App SQLite Access数据库

问:我无法在Documents文件夹中打开SQLite数据库:

应用程序:通用Windows(10)平台
开发:C#,Visual Studio 2015
SQLite:使用SQLite.net
目标:Windows 10桌面和Windows 10手机

部署:从Visual Studio或Sideloaded(不需要存储部署)

using SQLite;
using SQLite;   
using SQLite.Net;   
using SQLite.Net.Async;   
using SQLite.Net.Attributes
Run Code Online (Sandbox Code Playgroud)

我可以:

打开并从项目中包含的数据库中读取内容:

using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), ".\\mydb.db3"))
{
//Read queries
}
Run Code Online (Sandbox Code Playgroud)

打开/创建和读/写数据库到apps工作区:

string path = Path.Combine
(Windows.Storage.ApplicationData.Current.LocalFolder.Path,"another.db3");

using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
{
//CRUD
}
Run Code Online (Sandbox Code Playgroud)
  • 将another.db3复制到Documents
  • 从那里复制到外部存储设备(SD卡)

我不能

  • 在Documents或SD中打开数据库

我使用FilePicker选择Documents或SD中的db
然后在尝试打开数据库连接时使用File.Path属性

Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync();  
string path = File.Path;
Run Code Online (Sandbox Code Playgroud)

我尝试打开该连接时收到以下错误消息:

抛出异常:SQLite.Net.dll中的"SQLite.Net.SQLiteException"
SQLite-GetAllVendors:无法打开数据库文件:C:\ Users\me\Documents\another.db3(CannotOpen)

添加了SQLite .db和.db3文件关联.

      <Extensions>
        <uap:Extension Category="windows.fileTypeAssociation">
          <uap:FileTypeAssociation Name=".db"> …
Run Code Online (Sandbox Code Playgroud)

c# database sqlite uwp

7
推荐指数
1
解决办法
3590
查看次数

列表框项目之间的垂直间隙(删除?)

我的列表框是从使用 DataTemplate 进行数据绑定的对象列表驱动的数据,例如:

            <ListBox x:Name="TheMainListBox" 
                 ScrollViewer.IsVerticalRailEnabled="True" 
                 ScrollViewer.IsHorizontalRailEnabled="False" 
                 HorizontalAlignment="Left" 
                 VerticalAlignment="Top"
                 Height="540" 
                 ItemsSource="{Binding}"
                 Width="Auto"
                 Margin="0"
                 Padding="0"
                 Background="Yellow"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                 ScrollViewer.VerticalScrollBarVisibility="Auto" 
                 SelectionChanged="TheMainListBox_SelectionChanged" 
                 DoubleTapped="TheMainListBox_DoubleTapped"  
                 >
Run Code Online (Sandbox Code Playgroud)

模板:

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid or Stackpanel Background="Blue"
                         Padding="0"                                    
                         BorderBrush="Black"
                         BorderThickness="1"
                         Margin="0"
                     >
                     .... Binding Textboxes/blocks
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

我最终得到一个黄色容器,即列表框,..里面有蓝色矩形,即列表框项目,但它们之间有一个垂直间隙。我可以设置负的垂直顶部边距,但这很粗糙,并且不适用于顶部项目。如何将项目之间的垂直间隙减小到零。

如果创建一个包含静态项的 ListBox,每个项都位于 ListBoxItem 容器中,例如:

                <ListBoxItem BorderThickness="1" Width="100" Height="50"
                  BorderBrush="Black" Background="Red"/>
Run Code Online (Sandbox Code Playgroud)

一切都按要求进行。

那么如何使用 ItemTemplate/DataBinding 消除项目之间的垂直间距呢? 这是关键任务,请提前致谢。

c# xaml listbox win-universal-app

5
推荐指数
1
解决办法
2239
查看次数

标签 统计

c# ×2

database ×1

listbox ×1

sqlite ×1

uwp ×1

win-universal-app ×1

xaml ×1