@dovid
על הtabcontrol
private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (tabControl.SelectedIndex == 0) { SearchTextBox.Focus(); SearchTextBox.SelectAll(); }
}
@dovid
על הtabcontrol
private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (tabControl.SelectedIndex == 0) { SearchTextBox.Focus(); SearchTextBox.SelectAll(); }
}
סליחה על הכותרת קצת הסתבכתי איתה בכל אופן השאלה שלי היא כך:
יש לי tabcontrol בwpf בתוך הtabcontrol יש לי שני tabpages ובאחד מהם יש listbox
ניתקלתי בבעיה שהevent של selectionchanged מופעל כל פעם שאני לוחץ על הlistbox
איך אפשר למנוע זאת?
יש לי קוד בc# שקורא כמות של קבצים בבת אחת (בעצם תוכנת חיפוש פשוטה שאמורה לשמש את מי שאין לו מקום במחשב בשביל אינדקס) וכדי למהר את הפעולה אני משמתמש בThreading
נתקלתי בבעיה שאני לא מצליח לעדכן את הprogressbar תוך כדי פעולת הthreading כדי להראות התקדמות. (בwinforms הצלחתי על ידי invoke).
ניסיתי על ידי Dipatcher ללא הועיל.
ניסיתי על ידי Binding ללא הועיל.
בעצם מה שקורה שאם אני עושה פעולת דמע
Thread.Sleep(100); // Simulating some work being done
אז הכל טוב
אבל ברגע שאני מתחיל לקרוא קבצים שום כלום.
מצו"ב הקוד שלי של הbinding אשמח לקבל עזרה
<Window x:Class="WPF_BInding.ProgressBarBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF_BInding"
mc:Ignorable="d"
Title="ProgressBarBinding" Height="450" Width="800">
<Grid>
<StackPanel>
<ProgressBar Height="25" Name="progressBar" Minimum="0" Maximum="100" Value="{Binding PercentDone}" />
<Button Content="Start Task" HorizontalAlignment="Center" VerticalAlignment="Bottom" Click="StartTask_Click" />
</StackPanel>
</Grid>
</Window>
public partial class ProgressBarBinding : Window, INotifyPropertyChanged
{
private int _percentDone;
private int _progressBarMaximum = 100;
public int PercentDone
{
get { return _percentDone; }
set
{
if (_percentDone != value)
{
_percentDone = value;
OnPropertyChanged(nameof(PercentDone));
}
}
}
public int ProgressBarMaximum
{
get { return _progressBarMaximum; }
set
{
if (_progressBarMaximum != value)
{
_progressBarMaximum = value;
OnPropertyChanged(nameof(ProgressBarMaximum));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ProgressBarBinding()
{
InitializeComponent();
DataContext = this; // Set the data context to the MainWindow itself
progressBar.Maximum = ProgressBarMaximum; // Set the initial Maximum value
}
אני מנסה ללמוד קצת יותר על binding בפקד TreeView ב WPF על פי הכתבה הזו:
https://wpf-tutorial.com/treeview-control/treeview-data-binding-multiple-templates/
https://wpf-tutorial.com/treeview-control/handling-selection-expansion-state/
את השלב הראשון של binding ל-Hirarchy הצלחתי לעשות
אבל את השלב השני של binding לפעולות של ISEXPANDED ו ISSELCTED אני לא מצליח לעשות כלומר זה לא עובד לי
אשמח לקבל הדרכה בעניין ממי שיכול. תודה מראש
מצו"ב הקוד שעשיתי.
<Window x:Class="WPF_BInding.TreeViewBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF_BInding"
mc:Ignorable="d"
Title="TreeViewBinding" Height="450" Width="800">
<Grid>
<StackPanel>
<TreeView x:Name="treeView">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:myTreeViewItem}" ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Header}" Tag="{Binding Tag}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
<WrapPanel>
<Button Name="btnSelectNext" Click="btnSelectNext_Click" Width="120">Select next</Button>
<Button Name="btnToggleExpansion" Click="btnToggleExpansion_Click" Width="120" Margin="10,0,0,0">Toggle expansion</Button>
</WrapPanel>
</StackPanel>
</Grid>
</Window>
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace WPF_BInding
{
/// <summary>
/// Interaction logic for TreeViewBinding.xaml
/// </summary>
public class myTreeViewItem : TreeViewItemBase
{
public string Header { get; set; }
public string Tag { get; set; }
public ObservableCollection<myTreeViewItem> Items { get; set; } = new ObservableCollection<myTreeViewItem>();
}
public class TreeViewItemBase : INotifyPropertyChanged
{
private bool _isSelected;
private bool _isExpanded;
public bool IsSelected
{
get { return this._isSelected; }
set
{
if (value != this._isSelected)
{
this._isSelected = value;
NotifyPropertyChanged("_isSelected");
}
}
}
public bool IsExpanded
{
get { return this._isExpanded; }
set
{
if (value != this._isExpanded)
{
this._isExpanded = value;
NotifyPropertyChanged("_isExpanded");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public partial class TreeViewBinding : Window
{
public TreeViewBinding()
{
InitializeComponent();
List<myTreeViewItem> items = new List<myTreeViewItem>();
myTreeViewItem rootItem = new myTreeViewItem { Header = "root", IsExpanded = false };
myTreeViewItem child1 = new myTreeViewItem { Header = "child 1" , IsExpanded = false};
myTreeViewItem child2 = new myTreeViewItem { Header = "child 2", IsExpanded = false };
rootItem.Items.Add(child1);
rootItem.Items.Add(child2);
myTreeViewItem rootItem2 = new myTreeViewItem { Header = "root", IsExpanded = false };
myTreeViewItem child3 = new myTreeViewItem { Header = "child 1", IsExpanded = false };
myTreeViewItem child4 = new myTreeViewItem { Header = "child 2", IsExpanded = false };
rootItem2.Items.Add(child3);
rootItem2.Items.Add(child4);
items.Add(rootItem);
items.Add(rootItem2);
treeView.ItemsSource = items;
}
private void btnSelectNext_Click(object sender, RoutedEventArgs e)
{
}
private void btnToggleExpansion_Click(object sender, RoutedEventArgs e)
{
if (treeView.SelectedItem != null)
{
myTreeViewItem treeViewItem = treeView.SelectedItem as myTreeViewItem;
if (treeViewItem != null)
{
treeViewItem.IsExpanded = !treeViewItem.IsExpanded;
}
}
}
}
}
פתרון מאולתר:
אני יוצר list ששומר את כל הwebviews בתוך thisaddin ואז כך שהתוכנה מתעלמת מכל שגיאה שקורית בסגירת הwebview
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
try
{
foreach (WebView2 webView in webviewlist)
{
webView.Dispose();
}
}
catch (Exception){ }
}
לאחרונה התוודעתי לעולם של יוניקוד וגיליתי שיש שם הרבה סמלים מאוד שימושיים לדוגמא קישוטים לכותרות ועוד ועוד.
הנה דוגמא:
http://xahlee.info/comp/unicode_typography_ornaments.html
השאלה שלי האם סמלים אלה יכולים להיות זמינים בוורד איכשהו.
תודה מראש.
כמובן שיש את זה

אבל זה לא מתחיל לכסות את הפוטנציאל של יוניקוד:
נתקלתי בבעיה לכאורה עם הפוקוס של הפקד webbrowser בvsto
כאשר עוברים מהמסמך לtaskpane כמה פעמים לפעמים הפוקוס לא נקלט וזה מתבטא בכך שקיצורי המקשים כגון cntrl + c לא עובדים.
(כמובן שאם הייתי יכול להשתמש עם webview הייתי משתמש) אבל לעת עתה לא מצאתי דרך).
@dovid
אני רואה עכשיו שיש הבדל בין איך אני עושה zoom
אם אני לוחץ על cntrl +
אז זה אכן מתאים
אבל אם על ידי ה-touchpad אז לא.
יש מה לעשות?
מישהו איך עושים בjs שהתוכן יתאים את עצמו לרוחב העמודה גם אם המתמש עושה zoom in?
מצו"ב תמונה של האתר תחומים כאשר עשיתי zoom in

כמו שאתם רואים חצי מהתוכן לא זמין אלא על ידי גלילה.
אז איך עושים שהתוכן יתאים את עצמו באופן אוטומטי.
עשיתי ככה ועבד
string tempWebCacheDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
webView2Environment = await CoreWebView2Environment.CreateAsync(userDataFolder: tempWebCacheDir);
await browser.EnsureCoreWebView2Async(webView2Environment);
browser.NavigateToString("aaa");
אבל כשאני סוגר את וורד אני מקבל שגיאה זו
System.InvalidCastException
HResult=0x80004002
Message=לא ניתן לבצע cast של אובייקט COM מסוג 'System.__ComObject' לסוג ממשק 'Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller'. פעולה זו נכשלה מכיוון שקריאת ה- QueryInterface לרכיב ה- COM עבור הממשק עם IID '{4D00C0D1-9434-4EB6-8078-8697A560334F}' נכשלה עקב השגיאה הבאה: No such interface supported (חריג מ- HRESULT: 0x80004002 (E_NOINTERFACE)).
Source=mscorlib
StackTrace:
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.get_CoreWebView2()
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.get_CoreWebView2() in Microsoft.Web.WebView2.Core\CoreWebView2Controller.cs:line 58
at Microsoft.Web.WebView2.Wpf.WebView2.Uninitialize(Boolean browserCrashed)
at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean disposing)
@dovid
פרוייקט נקי עובד.
מסתבר שהבעיה דוקא כשאני עושה בvsto
מצו"ב המידע שביקשת


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using System.Windows;
using System.Windows.Forms;
namespace TestVstoWebView
{
public partial class ThisAddIn
{
private Microsoft.Office.Tools.CustomTaskPane taskPane;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
UserControl hostControl = new UserControl();
hostControl.Load += HostControl_Load;
taskPane = this.CustomTaskPanes.Add(hostControl, "תורת אמת");
taskPane.Visible = true;
taskPane.Width = 450;
}
private void HostControl_Load(object sender, EventArgs e)
{
Window window = new Window();
webviewcontrol webviewcontrol = new webviewcontrol();
window.Content = webviewcontrol;
window.Show();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
<UserControl x:Class="TestVstoWebView.webviewcontrol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestVstoWebView"
xmlns:webview ="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<webview:WebView2 x:Name="webView"/>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestVstoWebView
{
/// <summary>
/// Interaction logic for webviewcontrol.xaml
/// </summary>
public partial class webviewcontrol : UserControl
{
public webviewcontrol()
{
InitializeComponent();
InitializeWebview();
}
async void InitializeWebview()
{
await webView.EnsureCoreWebView2Async();
webView.NavigateToString("test string");
}
}
}
יצויין שכנ"ל אותו הקוד בדיוק עובד בפרוייקט רגיל הבעיה מתחילה רק בvsto
@dovid
אין לי מבנה אני בונה אותו מתוך תיקיות
public static void PopulateTreeView(TreeView treeView, string booksDirectory, bool isMyBooks)
{
Z_SourceFolder z_SourceFolder = new Z_SourceFolder();
if (Directory.Exists(booksDirectory))
{
DirectoryInfo rootDirectory = new DirectoryInfo(booksDirectory);
CreateTreeView(rootDirectory, treeView, isMyBooks);
}
}
static void CreateTreeView(DirectoryInfo directory, ItemsControl parentItem, bool isMyBooks)
{
foreach (var subDirectory in directory.GetDirectories())
{
TreeViewItem subItem = CreateDirectoryItem(subDirectory, isMyBooks);
parentItem.Items.Add(subItem);
CreateTreeView(subDirectory, subItem, isMyBooks);// Recursively populate for subdirectories
}
foreach (var file in directory.GetFiles())
{
TreeViewItem fileItem = CreateFileItem(file, isMyBooks);
parentItem.Items.Add(fileItem);
}
}
static TreeViewItem CreateDirectoryItem(DirectoryInfo directory, bool isMyBooks)
{
string name = Z_TranslatorClass.TranslateFolderName(directory.Name);
name = Regex.Replace(name, "[0-9]+|_", "");
TreeViewItem item = new TreeViewItem();
if (isMyBooks == true) { item.Foreground = System.Windows.Media.Brushes.Firebrick; }
item.Header = "🗀 " + name;
item.Tag = directory.FullName;
return item;
}
static TreeViewItem CreateFileItem(FileInfo file, bool isMyBooks)
{
string name = file.Name.Replace(".txt", "");
if (file.FullName.Contains("ToratEmetInstall"))
{ name = Z_TranslatorClass.TranslateFilename(file.FullName); }
name = Regex.Replace(name, "[0-9]+|_", "");
TreeViewItem item = new TreeViewItem();
if (isMyBooks == true) { item.Foreground = System.Windows.Media.Brushes.Firebrick; }
item.Header = "📑 " + name;
item.Tag = file.FullName;
return item;
}
אני מחפש פקד checktreeview עבור wpf אשמח אם מישהו מכיר משהו מוכן זה מאוד יעזור
בכל אופן לבינתיים ניסיתי לעשות זאת בעצמי
להוסיף את checkbox היה די קל אבל מאוד מקשה עלי העובדה שאין לי גישה ישירה בין ה- checkbox ל- treeview רק על ידי כל מיני פקודות שמחפשים את הchild של הtreeview item או רת הparent של הcheckbox
אם מישהו יודע איך עושים את זה אשמח לקבל הדרכה. תודה
הנה הקוד שיש לי לבינתיים
<UserControl.Resources>
<Style TargetType="CheckBox">
<EventSetter Event="Checked" Handler="CheckBox_Checked"/>
<EventSetter Event="Unchecked" Handler="CheckBox_Unchecked"/>
</Style>
<Style TargetType="TreeViewItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="checkBox"/>
<TextBox Text="{Binding Path=Header, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}}"
BorderBrush="Transparent" Background="Transparent"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
ניסיתי לעשות פקודת navigate to string בפקד webview בC# wfp
למעישה זה מחזיר לי שגיאה שהcore לא נטען
עשיתי EnsureCoreWebView2Async( );
וגם לא עזר
מישהו יודע מה צריך לעשות כדי להפעיל פקודה זו כראוי?
תודה
קלטתי את הטעות שלי ב'וד הקודם צריך להפוך את הסדר קודם לקלוט את המקש ואז את הmodifier
ככה
private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Key.C == e.Key && Keyboard.Modifiers == ModifierKeys.Control)
{
e.Handled = true;
}
}
ועוד משהו חשוב יש לעשות e.handeled כדי למנוע פעולה בלתי רצויה למשל בתוך textbox שיקליד לך גם את האות C
אבל לא הצלחתי לעשות עם שלוש מקשים כמו:cntrl+shift+c
@dovid כתב בקיצורי מקשים באפליקציית C# WPF:
אם גלובליים אתה מתכוון לא משנה באיזה חלון/פקד של האפליקציה שלך, אז אתה צריך לדאוג להירשם בכל Window לאירוע PreviewKeyDown.
כוונתי הייתה לאפליקצייה שלי סליחה שלא פירטתי.
בכל אופן previewkeydown לכאורה נותן לי את האופציה למקש אחד לא קובינציה של מקשים.
זה מה שניסיתי
private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.C)
{
// Handle Ctrl + C here
MessageBox.Show("Ctrl + C pressed!");
}
}
הוא קולט את הcntrl ולא את ה-c
אגב: למה previewkeydown ולא keydown?
עדכון:
בס"ד מופץ כעת קידודון תורת אמת האמור לסייע בהתאמת קבצי טקסט עבור תוכנת תורת אמת
https://mitmachim.top/post/735200
אשמח אם מישהו יכול להדריך אותי איך יוצרים קיצורי מקשים גלובליים באפליקצייה של wpf ב C#
לדוגמא cntrl +o לפתיחת קובץ וכן הלאה
תודה מראש
@סמינר-דוד
אם אין לו אינטרנט אז יש גמ"ח לזה עם סניפים בכל הארץ
0548449145