|
Richard, Thank you very much.
|
|
|
|
|
Hi,
I'm coding a little application for my company, the idea is very simple:
I would like to copy a directory from a server location to a local folder and I want to show the progress by using a progress bar.
I already integrated the copy of the directory by using this code:
using System;
using System.IO;
class DirectoryCopyExample {
static void Main() {
DirectoryCopy(".", @".\temp", true);
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) {
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
if (!dir.Exists) {
throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
if (!Directory.Exists(destDirName)) {
Directory.CreateDirectory(destDirName);
}
FileInfo[] files = dir.GetFiles();
foreach(FileInfo file in files) {
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}
if (copySubDirs) {
foreach(DirectoryInfo subdir in dirs) {
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
For the integration of the progress bar according to the number of files/sizes I can't find anything
Can someone help me with this?
Thank you!
|
|
|
|
|
Member 12674678 wrote: For the integration of the progress bar according to the number of files/sizes I can't find anything Where did you look? Google has lots of suggestions: wpf progress bar - Google Search[^].
|
|
|
|
|
i found this code (thanks for your link):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace copynestedfolderformapplication
{
public partial class Form1 : Form
{
int maxbytes = 0;
int copied = 0;
int total=0;
public Form1()
{
InitializeComponent();
}
private void copybtn_Click(object sender, EventArgs e)
{
Copy1(@"F:\Posts", @"G:\copydata");
MessageBox.Show("Done");
}
public void Copy1(string sourceDirectory, string targetDirectory)
{
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
GetSize(diSource, diTarget);
maxbytes = maxbytes / 1024;
progressBar1.Maximum = maxbytes;
CopyAll(diSource, diTarget);
}
public void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fi in source.GetFiles())
{
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
total += (int)fi.Length;
copied += (int)fi.Length;
copied /= 1024;
progressBar1.Step =copied;
progressBar1.PerformStep();
label1.Text = (total/1048576).ToString() + "MB of " + (maxbytes/1024).ToString() + "MB copied";
label1.Refresh();
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
public void GetSize(DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fi in source.GetFiles())
{
maxbytes += (int)fi.Length;
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
GetSize(diSourceSubDir, nextTargetSubDir);
}
}
}
}
where do i need to include the Backgroundworker in this code?
|
|
|
|
|
That's Windows Forms, not WPF. Your first sample was a Console application. How much do you currently have as WPF?
This space for rent
|
|
|
|
|
|
That doesn't answer the question I asked - you might as well have replied with "I like cheese". How much do you currently have as WPF?
This space for rent
|
|
|
|
|
I have been trying to do this without luck. What I'm trying to do is use an Outlook email link to run a local WPF exe with a parameter. I have been trying several things. First I created a .bat file and tried to kick it off directly from the email link (and Word link):
c:\users\steve\debug\MasterPage.bat 100
The batch files looks like this:
C:\users\steve\debug\MasterPage.exe %1
So that doesn't work so I changed the link to point to a html file running a JavaScript function calling the exe directly:
function callProgram()
{
var objShell = new ActivexObject("Shell.Application");
objShell.ShellExecute("cmd.exe", "C:\\cd C:\\Debug\\MasterPage.exe 1", "C:\\WINDOWS\\system32", "open", 1);
}
Nothing seems to work. If anyone can help please do.
|
|
|
|
|
Any half-decent email client will not execute Javascript in the body of the message, and will not allow links to launch local applications. If they did, it would be a major security vulnerability.
Give your users a command to copy and paste into the "Run" dialog (Win+R).
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I found the answer:
script language=JavaScript
function launchExecutable(executableFullPath)
{
var shellActiveXObject = new ActiveXObject("WScript.Shell");
shellActiveXObject.Run(executableFullPath, 1, false);
shellActiveXObject = null;
}
script
|
|
|
|
|
That might work in your environment but it won't work in mine. Yes, we use Outlook/Exchange. Policies prevent us from doing what you came up with, for very obvious security reasons.
|
|
|
|
|
That is only ever going to work on your system so there is little point in trying to run it from an email message.
|
|
|
|
|
Create a service (Windows service; FileWatcher event handler; SQL Server agent; whatever) that monitors for the arrival and related events of the email(s) in question; and then kicks off the WPF app.
Or have the WPF app "hide" (and monitor) until the email arrives and triggers a "show".
Event triggers and handlers.
|
|
|
|
|
I understand having a windows service monitor an event but what event in the email would kick off the Windows service starting the app and how would the parameter be accessed by the app on startup?
|
|
|
|
|
You start by examining how your mail is received, where it is stored, and what events are associated with it. At the very least, the contents of a given folder (or database) will be updated which can be monitored by a File Watcher (or other "monitor") class instance.
Get your "link" to save something if you can't figure the rest out.
|
|
|
|
|
I have a class that derives from Window and I use it for ALL windows in my application. I have a resource dictionary for themes contained in App.xaml, which looks like this:
<Application [...]>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="ThemeDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/MyTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
[...]
</Application>
The style for my derived window type is located in an external assembly and declared using Generic/Themes.xaml pattern.
For switching the theme, I remove the existing theme dictionary and replace it with the new one. Oddly, the changes in styles only reflect in MainWindow and not in any additionally created windows.
My derived window type is styled like this:
<ControlTemplate x:Key="WindowTemplate" TargetType="{x:Type Controls:CustomWindow}">
[...]
</ControlTemplate>
<Style x:Key="{x:Type Controls:CustomWindow}" TargetType="{x:Type Controls:CustomWindow}" BasedOn="{StaticResource CustomWindowStyle}">
[...]
</Style>
Note, the theme specified at design-time always works in ALL windows; however, any themes specified at run-time only apply to MainWindow and never additional windows.
Any idea why this is?
|
|
|
|
|
Have you tried calling BeginInit and EndInit on the main resource dictionary?
ResourceDictionary toRemove = ...;
ResourceDictionary toAdd = ...;
Resources.BeginInit();
try
{
if (toRemove != null)
{
Resources.MergedDictionaries.Remove(toRemove);
}
if (toAdd != null)
{
Resources.MergedDictionaries.Add(toAdd);
}
}
finally
{
Resources.EndInit();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I applied your suggestion and the method that sets the dictionary is now as follows:
public Result Set(string Path)
{
Result Result = null;
ResourceDictionary NewDictionary = this.Get(Path);
this.Dictionary.BeginInit();
try
{
if (this.Dictionary != null && NewDictionary != null)
{
this.Dictionary.Clear();
this.Dictionary.MergedDictionaries.Add(NewDictionary);
Result = new Success();
}
}
catch (Exception e)
{
Result = new Error(e.Message);
}
finally
{
this.Dictionary.EndInit();
}
return Result;
}
Where NewDictionary is a resource dictionary read from a file and this.Dictionary is the resource dictionary containing the merged dictionaries.
Unfortunately, this doesn't change anything.
|
|
|
|
|
I just found this in our app's CTOR:
System.Windows.FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
MSDN Says [^]
Gets or sets a value that indicates whether a data-bound TextBox should display a string that is identical to the value of the source its Text property
As is typical with MSDN, this explanation says nothing of value.
Why wouldn't a textbox display what's in its Text property by default?
Anyone ever used this? Can you shed some light on what this really means?
If it's not broken, fix it until it is
|
|
|
|
|
I've never used it but it looks like it is referring not to the Text property of the TextBox, but to the source that is data bound to the Text property.
From looking at the code it appears it has to do with an edge case where the TextBox is pushing a change back to the binding source but may not notice if the binding source has modified that string.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Just found this[^]
Seems like a good explanation, although this property seems to be because of a bug.
If it's not broken, fix it until it is
|
|
|
|
|
I have tried a lot of things without luck. What I'm trying to do is create a XAML TabControl that keeps all of the first five visible TabItems on the first row when the last two hidden TabItems become visible. What I want is for the two last TabItems to wrap when they become visible but keep the first five on the first row. I have tried to use a TextBlock with a LineBreak but when the last two TabItems become visible the fifth TabItem wraps with the new visible last two TabItems. Any help would be great.
|
|
|
|
|
The answer to my problem had to do with setting the widths of the collapsed tabs once they were changed to visible. What I did was give the newly visible tabs the correct width and they pushed the other tabs to the first row.
|
|
|
|
|
This is a very simple example, and I can't get it to work
My UserControl
<Grid>
<Border>
<TextBlock Text="{Binding DayNameCaption}"
Background="Green"
Foreground="White"
Height="25"
Width="75"/>
</Border>
</Grid>
Code Behind
public partial class MonthViewDayColumnHeader : UserControl
{
#region DP DayName
public static readonly DependencyProperty DayNameCaptionProperty =
DependencyProperty.Register("DayNameCaption",
typeof(string),
typeof(MonthViewDayColumnHeader),
new PropertyMetadata("Today",
new PropertyChangedCallback(OnDayNameCaptionChanged),
new CoerceValueCallback(CoerceDayNameCaption)));
public string DayNameCaption
{
get { return (string)GetValue(DayNameCaptionProperty); }
set { SetValue(DayNameCaptionProperty, value); }
}
private static void OnDayNameCaptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;
}
private static object CoerceDayNameCaption(DependencyObject d, object value)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;
return null;
}
#endregion
#region CTOR
public MonthViewDayColumnHeader()
{
InitializeComponent();
this.DataContext = this;
}
#endregion
}
Usage:
<Grid>
<schedule:MonthViewDayColumnHeader DayNameCaption="Monday"
Height="50"
Width="120"/>
</Grid>
The text "Monday" doesn't show up.
WTF IS WRONG HERE!!!!
If it's not broken, fix it until it is
|
|
|
|
|