我有一个PDF文件存储在数据库中作为字节数组.我正在从我的数据库中读取PDF字节数组回到我的应用程序中.
现在,我正在尝试使用RadPdfViewer显示PDF但它无法正常工作.
这是我的代码:
byte[] pdfAsByteArray= File.ReadAllBytes(@"C:\Users\Username\Desktop\Testfile.pdf");
//Save "pdfAsByteArray" into database
//...
//Load pdf from database into byte[] variable "pdfAsByteArray"
using (var memoryStream = new MemoryStream(pdfAsByteArray))
{
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
}
Run Code Online (Sandbox Code Playgroud)
当我执行应用程序时,我得到一个空的PdfViewer.
问题:如何以正确的方式设置DocumentSource?
问题:如何处理流?(注意using不起作用)
注意:我不想避免将临时文件写入磁盘
编辑:
我想通了,但我对这个解决方案并不完全满意:
不工作:
using (var memoryStream = new MemoryStream(pdfAsByteArray))
{
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
}
Run Code Online (Sandbox Code Playgroud)
工作:
var memoryStream = new MemoryStream(pdfAsByteArray);
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
Run Code Online (Sandbox Code Playgroud)
我不知道teleriks RadPdfViewer组件是如何工作的,但我不想处理Stream.
我正在尝试在Where子句中创建一个带有4个参数的LINQ查询.这是一个Windows 8 App项目,我正在使用SQLite数据库.(SQLite实现)
这是代码片段:
public List<FinancialListBoxExpenseItem> retrieveExpenseItems(int month, int year, bool isPaid, StaticResources.FrequencyEnum frequencyEnum)
{
List<FinancialListBoxExpenseItem> tmpList = null;
connection.RunInTransaction(() =>
{
var items = from s in connection.Table<FinancialListBoxExpenseItem>()
where (s.expenseDateNextPayment.Month == month)
&& (s.expenseDateNextPayment.Year == year)
&& (s.expensePaidForCurrentPeriod == isPaid)
&& (s.expenseFrequencyTypeEnum == frequencyEnum)
select s;
tmpList = items.ToList<FinancialListBoxExpenseItem>();
});
return tmpList;
}
Run Code Online (Sandbox Code Playgroud)
它抛出一个NotSupportedAction:成员访问无法编译表达式Exception
我不知道这是什么意思,我应该怎么解决它.
编辑:它在没有where子句的情况下工作,因此错误必须与此where子句部分代码相关
正如您在下面的代码中看到的,我从Microsoft Sample获得
<SemanticZoom.ZoomedOutView>
<tiles:VariableTileControl x:Name="SemanticItemGridView"
AutomationProperties.AutomationId="itemGridView"
AutomationProperties.Name="Grouped Items"
Padding="80,87,10,0"
ItemsSource="{Binding Source={StaticResource SemanticgroupedItemsViewSource}}"
ItemTemplateSelector="{StaticResource SemanticMyTemplates}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"
Margin="0,0,0,-13"
HorizontalAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemContainerStyle="{StaticResource SemanticGridViewItemStyle}">
<tiles:VariableTileControl.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Margin="0,0,10,0"/>
</ItemsPanelTemplate>
</tiles:VariableTileControl.ItemsPanel>
<tiles:VariableTileControl.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel Margin="1,0,0,6" Orientation="Horizontal" MinWidth="280">
<Button AutomationProperties.Name="Group Title"
Content="{Binding Title}"
Click="Header_Click"
Style="{StaticResource TextButtonStyle}" Foreground="White" FontSize="28" Background="#FFD71921" FontWeight="Light"/>
<TextBlock x:Name="tbk" Text="TM" VerticalAlignment="Top" Visibility="{Binding Tm}"/>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="28" FontWeight="Light" Text="("/>
<TextBlock x:Name="txtNo" TextWrapping="Wrap" Text="{Binding No}" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="28" FontWeight="Light"/>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="28" FontWeight="Light" …Run Code Online (Sandbox Code Playgroud) 我的观点包含a Button和a UserControl.该UserControl还包含一个Button.我的View中的Button1和我的Button2都UserControl应该在ViewModel中调用相同的方法.

因此我需要'注入'(不知道如何调用它)RelayCommand进入UserControl.我认为依赖属性会很容易,但我无法让它工作.
我尝试了什么:
该UserControl包含在包含视图的XAML代码设置一个依赖属性UserControl:
用户控制代码:
public const string LoadDataCommandPropertyName = "LoadDataCommand";
public Action LoadDataCommand
{
get
{
return (Action)GetValue(LoadDataCommandProperty);
}
set
{
SetValue(LoadDataCommandProperty, value);
}
}
public static readonly DependencyProperty LoadDataCommandProperty = DependencyProperty.Register(
LoadDataCommandPropertyName,
typeof(Action),
typeof(GridViewPersistenceController),
new UIPropertyMetadata());
Run Code Online (Sandbox Code Playgroud)
查看Xaml代码:(在UserControl中使用dp)
<customControls:MyUserControl Grid.Column="1"
x:Name="RadGridViewSettingsPersistenceControl"
GridControl="{Binding ElementName=RadGridView}"
LoadDataCommand="{Binding ActionTest}"
/>
Run Code Online (Sandbox Code Playgroud)
UserControl中的LoadDataCommand绑定到ViewModel中的此属性
private const string ActionTestPropertyName = "ActionTest";
private Action actionTest;
public Action ActionTest
{
get …Run Code Online (Sandbox Code Playgroud) 我的 Buildprocess 工作正常,但对于一个非常小的项目需要将近 3 秒。
我怎样才能加快构建过程?
日志文件太大,无法发布。随意询问有关记录器输出的问题,然后我将发布请求的部分。
用于构建项目的 C# 方法
private void CompileCode()
{
using (var buildManager = new BuildManager())
{
var result = buildManager.Build(this.CreateBuildParameters(), this.CreateBuildRequest());
if (result.OverallResult == BuildResultCode.Failure)
{
// Error handling
var stringbuilder = new StringBuilder();
using (var reader = new StreamReader(NameDebuggerLogFile))
{
stringbuilder.Append(reader.ReadToEnd());
}
throw new CompilerException(stringbuilder.ToString());
}
}
}
private BuildParameters CreateBuildParameters()
{
var projectCollection = new ProjectCollection();
var buildLogger = new FileLogger { Verbosity = LoggerVerbosity.Detailed, Parameters = "logfile=" + NameDebuggerLogFile };
var buildParameters …Run Code Online (Sandbox Code Playgroud) 如何在UpdateTasklist()方法之后执行SubmitWorkitem()方法而不阻塞线程?
private async void SubmitWorkitem(Workitem workitem)
{
await Task.Run(() => this.SubmitWorkitem(workitem));
//UpdateTasklist() should be executed after SubmitWorkitem() method.
//How can i achieve this without blocking the UI thread?
var locator = new ViewModelLocator();
locator.Task.UpdateTasklist();
}
Run Code Online (Sandbox Code Playgroud)
编辑:
该UpdateTasklist()方法连接到wcf webservice并要求所有打开的工作项.在SubmitWorkitem()方法中提交的工作项目仍然是答复的一部分.我认为这是因为UpdateTasklist()在提交工作项目之前执行.
请注意,这UpdateTasklist()也是一种异步方法
我在使用依赖属性方面遇到了一些问题.我想使用DP的值来初始化构造函数中的对象.
问题是Month始终为0(在构造时间期间),这会导致ExpenseDetailPageDataModel的错误初始化.在构造函数完成其工作之后,变量Month的值更改为正确的值(在本例中为11).
FinanceItemViewControl是一个自定义用户控件.
<common:FinanceItemViewControl Grid.Column="2" Month="11"/>
Run Code Online (Sandbox Code Playgroud)
Month是一个依赖属性,如下面的代码所示:
public sealed partial class FinanceItemViewControl : UserControl
{
...
public static readonly DependencyProperty MonthProperty = DependencyProperty.Register
(
"Month",
typeof(int),
typeof(FinanceItemViewControl),
new PropertyMetadata(
0, new PropertyChangedCallback(MonthProperty_Changed))
);
public int Month
{
get { return (int)GetValue(MonthProperty); }
set { SetValue(MonthProperty, value); }
}
#endregion
private static void MonthProperty_Changed(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
//TODO: trigger data reload
}
public FinanceItemViewControl()
{
this.InitializeComponent();
...
Debug.WriteLine("Constructor: " + Month);
detailPageDataModel = new ExpenseDetailPageDataModel(Month);
...
}
Run Code Online (Sandbox Code Playgroud) 我想创建一个WPF应用程序,该应用程序从数据库检索XAML代码并显示检索到的代码。
可以说数据库返回以下代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="mainGrid">
<Button Content="test case 1"
HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="100"
Click="TestCase1_OnClick"
Height="29"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我如何在运行时执行此代码(或者可能只是mainGrid的内容)?
假设我在xml中有以下代码片段:
<PanelWrapper id="RootPanel"
dock="Fill"
width="1092"
height="605"
backcolor="Transparent"
visible="True">
<ButtonWrapper id="button1"
dock="Left"
text="TestButton"
width="75"
height="605"
border-left="1"
border-top="1"
border-right="1"
border-bottom="1"
font-name="Tahoma"
font-size="9"
font-style="Regular">
</ButtonWrapper>
</PanelWrapper>
Run Code Online (Sandbox Code Playgroud)
我需要将xml代码转换为XAML.预期的结果应该如下所示:
<WrapPanel Name="RootPanel"
DockPanel.Dock="Left, Right, Top, Bottom"
Width="1092" Height="605"
Background="Transparent"
Visibility="Visible">
<Button Name="button1"
DockPanel.Dock ="Left"
Content="TestButton"
Width="75"
Height="605"
BorderThickness="1,1,1,1"
FontFamily="Tahoma"
FontSize="9"
FontStyle="Normal">
</Button>
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)
使用xsl样式表可以实现这种转换吗?
我特别要问这些变换:
从
border-left="1"
border-top="1"
border-right="1"
border-bottom="1"
Run Code Online (Sandbox Code Playgroud)
至
BorderThickness="1,1,1,1"
Run Code Online (Sandbox Code Playgroud)
或来自
visible="True"
Run Code Online (Sandbox Code Playgroud)
至
Visibility="Visible"
Run Code Online (Sandbox Code Playgroud) c# ×8
wpf ×4
xaml ×4
windows-8 ×2
.net-4.5 ×1
async-await ×1
asynchronous ×1
command ×1
compilation ×1
database ×1
linq ×1
msbuild ×1
msbuild-4.0 ×1
mvvm ×1
pdf ×1
performance ×1
runtime ×1
sqlite ×1
telerik ×1
winrt-xaml ×1
xml ×1
xslt ×1