|
Thank you, but i want to random image not byte..
|
|
|
|
|
You'll have to define what you mean by "random image" because I would have suggested the exact same thing. Store a bunch of random bytes in an array and treat that as image data.
|
|
|
|
|
Hi,
I am working on a WPF application. The application uses Infragistics controls such as Ribbon Controls and XamDockManager. It has a File Menu wherein I have provided a Save menu item to save the items on the canvas to a file. On click of Save button, Save Dialog opens to provide the File name and file is saved at the defined location.
The saving process is quite time consuming and in order to show something to the user, I have used the WaitCursor.
I have used a class similar to the one mentioned(UiServices.ShowWaitCursor) in the below thread.
http://stackoverflow.com/questions/7346663/how-to-show-a-waitcursor-when-the-wpf-application-is-busy-databinding[^]
http://stackoverflow.com/questions/3480966/display-hourglass-when-application-is-busy[^]
The usage is like this
public void WriteToFile(string fileName)
{
UiServices.SetBusyState();
_customFileWriter.WriteToFile(fileName);
}
This works fine, if we just save the things on the canvas into a file. However, if fails in the below scenario.
The application has a canvas where I display some UI elements. On double click of the UI element, we launch a Windows form in the Infragistic ContentPane.
We have a modeless dialog opened and perform File -> Save and provide a file name, the cursor stays indefinitely. It goes only once we click on the Canvas. The DispatcherTimer_Tick is fired only when we click on the Canvas which resets the cursor.
The DispatcherPriority is ApplicationIdle.
Another observation is, this happens only when we open the Save dialog through the File -> Save. It works fine if we open the Save dialog through Ctrl + S key combinations.
Is there a way I can debug the non firing of DispatcherTimer.Tick event or any other way to handle this?
I created a simple WPF application and it works fine in that.
MainWindow.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>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu Height="36" Name="menu1" Margin="12,0,439,197">
<MenuItem Header="_File" Height="22" Name="menuitem1" Width="200" Margin="10, 10, 5, 5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Chocolate">
<MenuItem Header="Save..." Click="MenuItem_Click"/>
</MenuItem>
</Menu>
<Canvas Height="156" HorizontalAlignment="Left" Margin="81,77,0,0" Name="canvas1" VerticalAlignment="Top" Width="304" Background="#FF945050">
<Button Canvas.Left="128" Canvas.Top="49" Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
<TextBox Canvas.Left="48" Canvas.Top="128" Height="23" Name="textBox1" Width="120" />
</Canvas>
</Grid>
</Window>
MainWindow.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
form.Height = 200;
form.Width = 400;
form.TopMost = true;
form.Show();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
string fileName = SaveFileDialog();
UiServices.SetBusyState();
System.Threading.Thread.Sleep(3000);
}
private string SaveFileDialog()
{
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
Nullable<bool> result = dlg.ShowDialog();
string filename = string.Empty;
if (result == true)
{
filename = dlg.FileName;
}
return filename;
}
}
public static class UiServices
{
private static bool _isBusy;
public static void SetBusyState()
{
SetBusyState(true);
}
private static void SetBusyState(bool busy)
{
if (busy != _isBusy &&
Application.Current != null &&
Application.Current.Dispatcher != null)
{
_isBusy = busy;
Mouse.OverrideCursor = busy ? Cursors.Wait : null;
if (_isBusy)
{
new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, DispatcherTimer_Tick, Application.Current.Dispatcher);
}
}
}
private static void DispatcherTimer_Tick(object sender, EventArgs e)
{
var dispatcherTimer = sender as DispatcherTimer;
if (dispatcherTimer != null)
{
SetBusy(false);
dispatcherTimer.Stop();
}
}
}
}
Thanks in advance!
|
|
|
|
|
I can't execute your code (I don't have those libraries you use), but can you use another priority?
I don't know... maybe you have an animation or similar that is never really letting the application become idle.
Note: Seeing your code, you don't need to use a DispatcherTimer. It is enough to do a Dispatcher.BeginInvoke to call your delegate. This will also guarantee that it will execute only once, as soon as all the messages (including the actual one) are processed. In fact, I think your problem is that you never started your timer.
|
|
|
|
|
Hi
Hopefully this will be a quick question to answer, but personally I'm not sure which way to go.
Firstly I'm using SL5, MVVM, MEF, EF. I have a person entity - the person entity has a collection of account entities, address entities and order entities.
In my view I am displaying a list of the people on the left with the corresponding lists on the right (accounts, addresses, orders). When the person is changed in the list I obviously want the lists on the right to update.
Obviously it would be inefficient to just include the lists in the domain service query using the .Include() operation as it will return ALL the people with ALL the related list entities. This is where my dilemma is - when I change the person do I either:
Load each of these lists separately, each with their own completed events where I populate the view lists. Which is basically three extra calls to the DB.
OR
2. Call a different GetPeople query in the domain service where I pass in the current person ID and use the .Include() operation to include accounts, address and orders, but filter by the passed in PersonID. (i.e. return this.ObjectContext.People.Include("Accounts").Include("Addresses").Include("Orders").Where(p=>p.ID == PersonID);)
Any help is much appreciated.
Thanks.
|
|
|
|
|
Can I integrate WPF application in web application??
Detail:-
I am working in a website, in this I want to integrate a small WPF application. Can i do this?? for eg... I wanna open login/signin popUp ("which is created in WPF") in my web application to enter the user in main page.
or we can say that in any tutorial webpage, I want to insert demo application of WPF application.
If it is possible please let me know, how i can do this.
Thanks in advance.
|
|
|
|
|
|
If you are going to develop an application from scratch, you may also want to consider using Silverlight - this will give you scope to development for the web.
Note that any SL application can be run outside the browser too.
|
|
|
|
|
I'm working on an WPF MVVM application. The data entry screen has to have all it's fields disabled until the user clicks "Add" or "Edit", and also the fields cannot become enabled if the user does not have rights to that field.
So, I would like to bind all IsEnabled properties in the XAML to a single method on the ViewModel. I would need to pass in a string value which is the 'key' of the field. Then in the VM would use the key to check the rights. The method would be something like
public bool CanEnableField(string Key)
{
}
A converter would probably not work because that class won't know about the VM and the form's mode (Add/Edit).
I could bind each field's IsEnabled to individual properties on the VM and handle all this in the getter, but that would be a lot of properties in the VM.
Anyone have any thoughts on how to do this?
If it's not broken, fix it until it is
|
|
|
|
|
The best way is to have a bool Property in your VM, to which you caan bind the IsEnabled property of the relevant controls like this:-
VM:
public bool CanEnableField(string Key)
{
}
public bool EnableControls
{
get
{
return enableControls;
}
set
{
if (enableControls != value)
{
enableControls = value;
OnPropertyChanged("EnableControls");
}
}
}
View:
<Label Grid.Row="2" Content="Name : " HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="2,2,2,7" />
<TextBox Grid.Column="1" Grid.Row="2" Margin="2" IsEnabled="{Binding Path=EnableControls}" Text="{Binding Path=SelectedCustomer.Name, ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" />
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
If you're using .NET 4.0 or 4.5, you can combine a single property with a dynamic object to achieve this:
public interface ICanEnableField
{
bool CanEnableField(string key);
}
public sealed class CanEnableFieldHelper : DynamicObject
{
private readonly ICanEnableField _owner;
public CanEnableFieldHelper(ICanEnableField owner)
{
_owner = owner;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _owner.CanEnableField(binder.Name);
return true;
}
}
public class YourViewModel : ICanEnableField
{
private readonly CanEnableFieldHelper _helper;
public YourViewModel()
{
_helper = new CanEnableFieldHelper(this);
}
public dynamic CanEnable
{
get { return _helper; }
}
public bool CanEnableField(string key)
{
...
}
}
In you XAML, you can then bind to CanEnable.Key , which will return the result of calling CanEnableField("Key") :
<TextBox IsEnabled="{Binding Path=CanEnable.Field1}" ... />
When you need to change the state, you just need to raise the PropertyChanged event for the CanEnable property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I'll take a look at it
If it's not broken, fix it until it is
|
|
|
|
|
This worked perfect. Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
I have a combo box bound to an ObservableCollection<classmodel>. The entity passed into the view has an instance of a ClassModel. I want to select the item in the combo which matches the entite's ClassModel.
So far im lookping over the ObservableCollection to find the item:
foreach (var jobClass in Classes)
{
if (jobClass.Id == JobRevision.JobClass.Id)
{
SelectedClass = jobClass;
break;
}
}
is there a way to do this without loopping?
Thanks
If it's not broken, fix it until it is
modified 12-Jan-13 21:27pm.
|
|
|
|
|
Can't you bind the SelectedValuePath of the combo to the SelectedJobClass.ID
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Not sure I understand. Can you post an example?
If it's not broken, fix it until it is
|
|
|
|
|
It is just the standard combo binding or am I missing something?
<ComboBox x:Name="cboType" Grid.Row="2" Grid.Column="1" ItemsSource="{Binding AttrTypeList,Mode=TwoWay}"
DisplayMemberPath="AttrType"
SelectedValuePath="AttrTypeID"
SelectedValue="{Binding SelectedAttrCostume.AttrTypeID,Mode=TwoWay}"/>
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes, but what are 'AttrType' and 'AttrTypeID' and 'SelectedAttrCostume'? Are they properties on the entities in the AttrTypeList list?
If it's not broken, fix it until it is
|
|
|
|
|
|
Ok, I don't know what's wrong, but I still cannot get this to work...
My combo is bound to an ObservableCollection<lookupmodel>, as in:
private ObservableCollection<LookupModel> _Departments;
public ObservableCollection<LookupModel> Departments
{
get { return _Departments; }
set
{
if (_Departments != value)
{
_Departments = value;
RaisePropertyChanged("Departments");
}
}
}
private LookupModel _SelectedDepartment;
public LookupModel SelectedDepartment
{
get { return _SelectedDepartment; }
set
{
if (_SelectedDepartment != value)
{
_SelectedDepartment = value;
RaisePropertyChanged("SelectedDepartment");
}
}
}
Here is the lookup model:
public class LookupModel : _BaseModel
{
private int _Id = 0;
public int Id
{
get { return _Id; }
set
{
if (_Id != value)
{
_Id = value;
RaisePropertyChanged("Id");
}
}
}
private string _Caption = string.Empty;
public string Caption
{
get { return _Caption; }
set
{
if (_Caption != value)
{
_Caption = value;
RaisePropertyChanged("Caption");
}
}
}
}
And in the vie model I have:
SelectedDepartment = Job.Department;
Job.Department is an instance of a lookup model with the selected department in it.
When I run this, the department is not selected in the combo.
What am I doing wrong here???
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
In my resource file I have:
<!--*************************************************************************
* COLORS & BRUSHES
************************************************************************-->
<Color x:Key="TextForeColor">Black</Color>
<SolidColorBrush x:Key="TextForeColorBrush"
Color="{StaticResource TextForeColor}"/>
<!--*************************************************************************
* BASE STYLES
************************************************************************-->
<Style x:Key="BaseTextBlockStyle"
TargetType="TextBlock">
<Setter Property="FontSize" Value="12" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Foreground" Value="{StaticResource TextForeColorBrush}"/>
<Setter Property="FontStyle" Value="Normal"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
<Style x:Key="TextBlockStyle"
TargetType="TextBlock"
BasedOn="{StaticResource BaseTextBlockStyle}">
<Setter Property="Foreground" Value="{StaticResource DataEnteryTextBlockForeColorBrush}"/>
</Style>
<Style x:Ke
Then in a view I have:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
and
<!--Job Header Area-->
<GroupBox Header=" Job Information "
Grid.Row="0"
BorderBrush="SteelBlue"
Background="#E2F4FF"
Foreground="SteelBlue"
Height="100"
Margin="5"
FontSize="14"
FontStyle="Italic"
FontWeight="Bold">
<Grid>
<!--Job Number-->
<TextBlock Text="Job #: "
Grid.Row="0"
Grid.Column="0"
Style="{StaticResource TextBlockStyle}"
Margin="5,2,2,5"/>
<TextBlock Text="2013-0001"
Grid.Row="0"
Grid.Column="1"
MinWidth="55"
Style="{StaticResource TextBlockDataDisplayStyle}"
Margin="5,2,2,5"/>
The style on the groupbox is being applied to the TextBlocks and TextBoxes.
The style, color, and brush names are all correct.
Anyone see what Im doing wrong?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
I'm still very much a novice at XAML, but what does this line refer to?
<Setter Property="Foreground" Value="{StaticResource DataEnteryTextBlockForeColorBrush}"/>
I could not see any definition of DataEnteryTextBlockForeColorBrush .
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
From my deep knowledge of all things xaml (insert sarcasm smiley): When you create a style.xaml file that contains the style for DataEnteryTextBlockForeColorBrush. you can reference it via the app.xaml (Silverlight) and it becomes a static resource available to all views. You can also create the style in the view's xaml as a resource (grid.resource/usercontrol.resouce etc) and it becomes a static resource usable by that view only.
Hang on you answer more of these than I do!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As I said: "I'm still very much a novice at XAML". Pete O'Hanlon could answer this without drawing breath.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
In my project it's defined above the XAML I pasted. I didn't include it to save space
If it's not broken, fix it until it is
|
|
|
|