|
Yes. It works. Thank you. And for full short answer.
modified 11-Aug-16 0:55am.
|
|
|
|
|
You're welcome. Glad you got it working.
This space for rent
|
|
|
|
|
Not if he is binding to a List of strings!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have searched the internet and can't find an answer to my question. In one of my WPF XMAL pages which is a Views I am using a GridView to load and binding values for each DisplayMemberBinding row. What I need to do is raise a row selected event but the GridView does not contain that event. How do I create a row selected event for the WPF GridView?
|
|
|
|
|
Are you sure you mean a GridView[^]? That can only be used as a view mode for a ListView[^], which does have a SelectionChanged event[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes it is in a ListView. Now I see the SelectionChange event. How would you recommend determining which row was selected?
|
|
|
|
|
|
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.
|
|
|
|