我有一個使用UWP InkCanvas的UWP應用程序,帶有加載和保存墨水按鈕。我在一臺筆記本電腦上繪製了應用程序的繪圖,將繪圖保存爲gif(+嵌入式isf),並將gif文件發送到另一臺帶有較小屏幕的筆記本電腦進行試用。當切換PC InkCanvas筆畫時沒有以適當的邊界呈現PC
當使用相同的應用程序打開墨水時,在其他筆記本電腦上打開時,繪圖被裁剪在邊界處,就好像它不適合屏幕一樣,這可能是由於筆記本電腦的屏幕較小。
我試圖通過將其封裝在滾動查看器中來將InkCanvas整體調整大小,但繪圖遵循InkCanvas縮放,因此繪製仍然在邊界處被裁剪。與InkCanvas上的渲染轉換相同。加載墨水時,我也嘗試了StrokeContainer的複製粘貼方法。它不起作用,而且我覺得它體積龐大,因爲需要遍歷所有筆畫來選擇它們,然後複製粘貼。
我正在尋找一種方法來自動調整InkCanvas(首選)或Strokes的大小,使繪圖完全顯示在InkCanvas上,而不管筆記本電腦屏幕的大小如何。我期待這種情況在默認情況下發生,但有些情況下不會。
雖然我使用的代碼是很簡單的,我將它作爲一個開始:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Background="White" Grid.Row="1">
<InkCanvas x:Name="inkCanvas"/>
</Grid>
<StackPanel>
<Button Content="Load" Click="LoadButton_Click"/>
<Button Content="Save" Click="SaveButton_Click"/>
</StackPanel>
</Grid>
private async void LoadButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Clear();
openPicker.FileTypeFilter.Add(".isf");
openPicker.FileTypeFilter.Add(".gif");
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
using (var inputStream = stream.GetInputStreamAt(0))
{
await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(inputStream);
}
stream.Dispose();
}
}
你還可以包含'SaveButton_Click'事件處理程序嗎? – Laith