|
Is the Start property in the control readonly? What is the mechanism for updating this property?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The Start property is a readonly .NET property:
public DateTime Start
{
get { ... }
}
There is a static DependencyProperty behind the scenes:
public class Foo
{
public static DependencyProperty StartProperty;
}
Pete O'Hanlon wrote: What is the mechanism for updating this property?
If the user clicks a button in the 3rd party control, the .Start will change.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
modified on Wednesday, December 9, 2009 5:38 PM
|
|
|
|
|
Hello,
Fairly new to WPF so hope this isn't going to be a case of failing to RTFM but I just can't see what has gone wrong.
I am modifying an existing user control to show slightly different data in a list depending on a setting on the control. I have registered the dependency property, added a get;set to use it else where in code and it comes up in the Intellisense in the XAML file. However it is not set to the value I've set it to in the XAML when it is check in the controls constructor.
Here is the relevant bits of the user control:
public partial class StationGroupControl : UserControl
{
public StationGroupControl()
{
try
{
if (ShowAggregates != true)
...
public static DependencyProperty ShowAggregatesProperty =
DependencyProperty.Register("ShowAggregates",
typeof(Boolean),
typeof(StationGroupControl),
new FrameworkPropertyMetadata(false));
public Boolean ShowAggregates
{
get
{
return (Boolean)GetValue(ShowAggregatesProperty);
}
set
{
SetValue(ShowAggregatesProperty, value);
}
}
And the XAML:
<ResearchCtrl:StationGroupControl Name="MultStation" HorizontalAlignment="Left" Margin="-122,0,0,0" Validation.Error="Ctrl_Error" ShowAggregates="True"></ResearchCtrl:StationGroupControl>
Frustratingly this seemed to be working and I then refactored the code down to smaller chunks and it inexplicably stoppped working. It has me doubting if it was ever working properly.
Is there some issue with using a boolean? Something else I need to do? Any way of debugging what is actually happening?
I'm pushed for time on this so any suggestion gratefully received.
Robert.
|
|
|
|
|
You're testing the value in the constructor, but it's not being set until AFTER.
The XAML is going to first create the object, THEN start setting properties... So basically what's happening is:
1) Object created
2) Constructor fires, checking ShowAggregates value
3) XAML parser sets the Name property
4) XAML parser sets the HorizontalAlignment property
...
7) XAML parser sets ShowAggregates to true
EDIT: Oh, should have added... The solution is to hook the Initialized event, or override OnInitialized, and do the check there.
|
|
|
|
|
Thanks, as suspected if I'd read the "manual" more closely I'd have spotted that eventually, if I wasn't mildly panicking I probably would have.
Thanks again Ian!
|
|
|
|
|
Hello again,
I tried moving the code to the Initialized event but it still wasn't set. I've now moved to the Loaded event and it is there so that's where I've left it for the moment. Let me know if you think this might cause a problem.
Thanks,
Robert.
|
|
|
|
|
|
Hi,
Is there a way in xaml/wpf to freeze first item in listbox from scrolling?
Thanks
|
|
|
|
|
Here is the scenario:
1. Open Visual Studio 2008, create new project...
2. Select WPF Custom Control Library as the project type
3 Open the Generic.xaml resource dictionary located in the Themes folder
4. Add a simple brush such as:
<SolidColorBrush x:Key="BackgroundBrush" Color="Yellow"/>
5. Change the Background property of the nested Borer Control from
Background="{TemplateBinding Background}"
to
Background="{DynamicResource BackgroundBrush}"
Now when you compile and use this control in any project, the background will NOT be yellow. BUT, if you change the background property to be a StaticResource as such
Background="{StaticResource BackgroundBrush}"
...it will work. Why is this? Why does StaticResource work but not DynamicResource???
|
|
|
|
|
Hi,
I am working with a Silver light application with WCF service. In this I have a session variable names "UserId" which will be created in user login.aspx page. Now I need to access this current login UserId into my WCF service.
or
I need to access this UserId sesssion variable in the silver light page and then pass it to WCF service as parameter.
If any one have any idea ti implement any one of the above please reply me.
Thanks in advance.
|
|
|
|
|
|
I have another issue with the WPF Ribbon control when i have two buttons on the bottom of the Application menu button. When i'm running my app and i click on a button on one of my tabs, it pops up with a user dialog for the user to choose then close. The issue i'm having is when the user clicks on any of the buttons in the dialog and then closes it, the two buttons i have in the Application menu button are disabled for some reason until the user clicks on the menu bar again. Why is that? Is this a known issue or just a quirk in WPF Ribbon? Thanks in advance!
|
|
|
|
|
how do i disable the mouse scroll in the WPF ribbon bar?
i'm trying to disable this because of the tabs that i have in my ribbon bar shouldn't be accessed until they are properly called on. This causes issues when the user is able to scroll through the tabs
Any ideas or advice would be much appreciated! 
|
|
|
|
|
I have found a solution to this(or maybe a work around, not sure) that does what i want it to do
I found the answer here: http://blogs.infragistics.com/forums/p/6887/28951.aspx[^]
This disables the mouse scroll for when the mouse is over the Ribbon bar which is EXACTLY what i needed!
I replied to my own question so that if others had the same problem they could see this answer i found 
|
|
|
|
|
Hi, Im using WPF controls in MFC.IN one dialog i want to get these controls,textbox,button etc.,And for button i wrote function.But it shows error at bolded line as
error C3364: 'System::Windows::RoutedEventHandler' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function
HWND GetHwnd(HWND parent,CSampleWPF* view,int x, int y, int width, int height)
{
// Create an HwndSource WPF object
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters ("WPFSourceWindow");
sourceParams->PositionX = x;
sourceParams->PositionY = y;
sourceParams->Height = height;
sourceParams->Width = width;
sourceParams->ParentWindow = IntPtr(parent);
sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
HwndSource^ source = gcnew System::Windows::Interop::HwndSource(*sourceParams);
view->m_wpfTextBox = gcnew TextBox();
view->m_wpfTextBox->Width=100;
view->m_wpfTextBox->Height=20;
view->m_wpfTextBox->Text = "Some WPF Text";
source->RootVisual = view->m_wpfTextBox;
view->m_Button = gcnew Button();
view->m_Button->Height=60;
view->m_Button->Margin=Thickness(2);
view->m_Button->Background::set(Brushes::SkyBlue);
view->m_Button->Click += gcnew RoutedEventHandler(view->m_Button,&CSampleWPF::OnBtnExit); source->RootVisual = view->m_Button;
return (HWND) source->Handle.ToPointer();
}
void CSampleWPF::OnBtnExit(Object^ sender, RoutedEventArgs^ e)
{
AfxMessageBox(_T("Simple message box."));
}
And also in output,its shows only the button not the textbox.Wats the mistake??
Anu
|
|
|
|
|
Hi Peoples,
I have designed a application in WPF browser aplication template.
I need to Publish/Host the same in the IIS server, means i need to access the same from i.e or mozila browser.
can any one help me? how to do the same ,
Thanks in advance.
|
|
|
|
|
Hi!
I'm kinda new to WPF and there's a lot of way to do stuff, I'm getting a bit mixed up. I would appreciate if someone could check the way I'm trying to do things and tell me what I understood wrong.
I'm trying to have a simple Windows with a grid. The rows in the grid are dynamically filled. I want to have a template for each row so they contain the same controls. I also want to have a feedback on these controls (when the selection of the first combobox change, populate the second combobox differently). And finally, I want to be able to see the selected values for each row controls when the user press the OK button.
Here is my XAML code:
<Window x:Class="WpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication"
Title="MainWindow" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="RowTemplate"
DataType="{x:Type local:RowViewModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Variable "/>
<TextBlock Text="{Binding Path=Slot}"/>
</StackPanel>
<ComboBox Grid.Column="1"
ItemsSource="{Binding Path=FirstList}"
SelectionChanged="Combo1SelectionChanged"/>
<ComboBox Grid.Column="2"
ItemsSource="{Binding Path=SecondList}"
SelectionChanged="Combo2SelectionChanged"/>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="MainGrid">
</Grid>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right">
<Button Content="Ok"/>
<Button Content="Cancel"/>
</StackPanel>
</Grid>
</Window>
And my C# code:
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.ComponentModel;
using System.Collections.ObjectModel;
namespace WpfApplication
{
public class List1 : ObservableCollection<string>
{
public List1() : base()
{
Add("A");
Add("B");
Add("C");
}
}
public class List2 : ObservableCollection<string>
{
public List2(string basedOn) : base()
{
Add(basedOn + "1");
Add(basedOn + "2");
Add(basedOn + "3");
}
}
public class RowViewModel : INotifyPropertyChanged
{
private int m_slot = 0;
private List1 m_firstList = null;
private List2 m_secondList = null;
public RowViewModel(int Slot)
{
this.Slot = Slot;
this.FirstList = new List1();
this.SecondList = new List2(Slot.ToString());
}
public int Slot
{
get
{
return m_slot;
}
set
{
if(value != m_slot)
{
m_slot = value;
NotifyPropertyChanged("Slot");
}
}
}
public List1 FirstList
{
get
{
return m_firstList;
}
set
{
if (value != m_firstList)
{
m_firstList = value;
NotifyPropertyChanged("FirstList");
}
}
}
public List2 SecondList
{
get
{
return m_secondList;
}
set
{
if (value != m_secondList)
{
m_secondList = value;
NotifyPropertyChanged("SecondList");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for(int i=0; i<10; i++)
{
RowDefinition rowDef = new RowDefinition();
this.MainGrid.RowDefinitions.Add(rowDef);
ItemsControl item = new ItemsControl();
item.DataContext = new RowViewModel(i);
item.SetValue(Grid.RowProperty, i);
this.MainGrid.Children.Add(item);
}
}
private void Combo1SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Combo2SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}
My problem currently is that I don't know which type of control to add to the grid because it's probably not a ItemsControl, nor a ContentControl? Also, the "RowTemplate" can't seem to be visible in my C# code, so I can't tell it to use it to display. Another problem is that I don't have access to the viewmodel and combobox directly in my SelectionChanged event, so I can't re-populate my list from there. I should probably do this in a totally different way, but as I said I'm getting mixed up.
|
|
|
|
|
I believe this is a bug in WPF 3.5. I've done extensive testing with the ScaleTransform class and only certain ranges produce the artifacts, but the transitions are sudden: it works at one scaling, then add 4 pixels to the size of the image and the artifacts appear. That's a high level description. Now for the nitty gritty details.
If you're scaling images over a certain size, glaring artifacts will appear in the scaled images if the scaled images are larger than will fit in a box 2900x2900, or any size larger than the originals if the originals will not fit into a box 2900x2900. The larger the scaled images the worse the artifacts will be. How close the scaled images can be to the size of the original is non-linear. To avoid artifacts, the larger the original, the smaller the scaled images must be relative to the original images. The following data points were tested:
1. If you want to scale originals that fit in a 6000x6000 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear.
2. If you want to scale originals that fit in a 4288x4288 box, the scaled images can be no larger than 2904x2904, or artifacts in the scaled images will appear.
3. If you want to scale originals that fit in a 3008x3008 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear.
4. If you want to scale originals that fit into 2900x2900, you can't scale images into 2904x2904 without producing minor artifacts, but 2896x2896 produces no artifacts.
5. If you want to scale originals that fit into 1920x1920, you can scale images into a box as large as 4384x4384 without producing artifacts. 4388x4388 and larger produces artifacts.
6. If you want to scale originals that fit into 960x960, you can scale images into a box as large as 8772x8772 without producing artifacts. 8776x8776 and larger produces artifacts.
I don't know whether this bug has been fixed in .NET 4.0 but hope to get around to testing this in the near future. If anyone knows a workaround, please let me know.
modified on Saturday, December 5, 2009 8:06 PM
|
|
|
|
|
I don't completely understand the situation, are you enlarging or shrinking the images? You may want to post a picture too. As for the artifacts I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts. I think they changed the default in .NET 4.0 to improve performance.
Are the images photos or graphics, are you animating them?
If they contain 1px wide lines or grids you may need to look at the positioning of the element, this is improved in .NET 4 by using LayoutRounding there are workarounds for previous versions.
modified on Sunday, December 6, 2009 8:05 PM
|
|
|
|
|
Insincere Dave wrote: I don't complete understand the situation
Do you mean the situation in my application? The user invokes my image scaling operation, supplying me with a bitmap of a photograph. He specifies a pixel rectangle into which to scale the supplied image. He's supplying an image from his camera so the image could be anything up to 6000 pixels on a side. But my scaling function is intended to scale the image down for 1:1 viewing on conventional monitors, so something smaller than 2600 pixels on a side. ScaleTransform has no problem with scaling down to that size. But one of my beta customers wanted to scale from 4288 to 3008, and all hell broke loose.
Insincere Dave wrote: are you enlarging or shrinking the images?
Well, as you could see from my attached data, I was doing both. I can push things where artifacts appear for both enlarging or shrinking the images. However, the boundaries where the artifacts appear are outside of the documented purpose of my application. Therefore in my own testing I never ran into the problem. Only when one of my beta testers "pushed the envelope" as described above did the problem arise. I then set about to characterize the problem, which the six tests I document tries to do.
In previous years, I wrote a version of my current application in MFC/GDI+ that does not have this problem, and of course Photoshop doesn't have the problem. It' only when I try to scale an image into a box larger than 2900Hx2900W when the input image is larger than that box that artifacts occur. The scaled images are completely clean as long as they fit within that box. If the image exceeds that box by even 4 pixels in either width or height, the artifacts suddenly appear, and they're glaring.
If the default for .NET 4.0 was changed to improve performance, this sounds like the default for 3.5 was HighQuality and the default for 4.0 is LowQuality, which to me would be a step backwards. I'm using 3.5. I couldn't actually see from the MSDN documentation what the default is.
Insincere Dave wrote: You may want to post a picture too.
You mean the scaled output? I didn't know you could post pictures on this site. Can you? If so, how? Or do you mean post a Web link outside of this forum to a scaled image with the artifacts I'm generating? The scaled images with artifacts have large blotches of solid color, sometimes in parallel stripes running in various directions, and the colors seemingly have no relationship to the underlying color. In fact, the underlying colors may involve gradients, but the artifacts are single-color, solid blotches.
EDIT: The above paragraph was written from my faulty memory of what the artifacts look like. I have one of the images before me right now and can give a more accurate description (not that this is going to provide any additional insight):
The scaled images with artifacts have large, irregular blotches consisting of closely spaced vertical lines in a color that seems unrelated to what the real color should be. For example: closely spaced vertical lines of bright green where smooth yellow gradients should be, and closely spaced vertical lines of bright cyan where caucasian skin color should be. There are large extents of the image that have no artifacts at all in them, but from looking at the image, I can't determine what might be causing artifacts to appear in some places and not in others. The larger the input image, the greater the extent of the artifacts in the corresponding scaled image.
|
|
|
|
|
Insincere Dave wrote: I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts.
I tried this suggestion. Here is my first attempt with maxDestinationHeight set to 3008 and maxDestinationWidth set to 3008:
TransformedBitmap scaledBitmap = new TransformedBitmap();
if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
{
RenderOptions.SetBitmapScalingMode(scaledBitmap, BitmapScalingMode.HighQuality);
}
scaledBitmap.BeginInit();
scaledBitmap.Source = bitmapSource;
scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
scaledBitmap.EndInit();
I actually tried all the values that IntelliSense suggested. Besides HighQuality, I also tried Fant (whatever that means), Linear, LowQuality, NearestNeighbor, and the last, Unspecified. All values produce exactly the same artifacts as as my code without an explicit SetBitmapScalingMode. I looked through the other attached properties in RenderOptions and only EdgeMode.Aliased suggested itself, but it also produced exactly the same aliases.
Then I tried the following code with all the BitmapScalingMode values, and every one of them produced exactly the same glaring artifacts.
TransformedBitmap scaledBitmap = new TransformedBitmap();
scaledBitmap.BeginInit();
scaledBitmap.Source = bitmapSource;
scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
{
RenderOptions.SetBitmapScalingMode(scaledBitmap.Transform, BitmapScalingMode.HighQuality);
}
scaledBitmap.EndInit();
Hopefully I'm doing something wrong that you can easily spot.
|
|
|
|
|
I thought you were applying a RenderTransform to an Image, I didn't know you were working with TransformedBitmap.
I haven't been able to reproduce the issue yet.
The following for me scales a 4288x4288 px image image as expected:
JpegBitmapDecoder dec = new JpegBitmapDecoder(new Uri(@"test.jpg"),BitmapCreateOptions.None,BitmapCacheOption.Default);
var image = dec.Frames[0];
var targetSize = 2900.0;
var scale = targetSize/image.PixelWidth;
TransformedBitmap scaledBitmap = new TransformedBitmap();
scaledBitmap.BeginInit();
scaledBitmap.Source = image;
scaledBitmap.Transform = new ScaleTransform(scale, scale);
scaledBitmap.EndInit();
Content = new Image {Width = targetSize,Height = targetSize,Source = scaledBitmap};
If you could change the code so that it does cause the artifact I'll have another look but you may want to try the MSDN forums as you might get a reply from someone on the WPF team.
|
|
|
|
|
I thought I said a target size of 2900 would not produce artifacts, so of course you won't see any artifacts. Try a target size of 3008, like my beta tester. Or 2904 for that matter.
|
|
|
|
|
I had already tried 2904,5000 and didn't see anything. You could try forcing software rendering and see if it is a driver issue if not I don't have any more ideas.
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
|
|
|
|
|
Insincere Dave wrote: I had already tried 2904,5000 and didn't see anything.
I tried your code at 3008 and 5000, with my original image at 4288x2848. Resizing to 5000, the artifacts are so horrendous that the original image is barely visible. That same image at 3008 had some barely detectable artifacts, so perhaps you have some extremely simple image that doesn't show the problem. Try a full resolution, digital photograph of people from a modern 12 MPixel DSLR with a variety of colors from clothing and skin tones.
Insincere Dave wrote: You could try forcing software rendering and see if it is a driver issue
I'm not sure how your example would be used. RenderTargetBitmap also uses software rendering and at least I can get my arms round that. Would that accomplish the same thing you're suggesting?
Just a little more background: The original purpose of my scaling function was to provide a batch operation to scale full resolution images straight out of the camera down to a size that can be shown on commonly available monitors 1:1 in a photo viewing application. The batch operation can operate on a single folder or recursively, down a folder tree, so the batch operation can theoretically scale thousands of images with a single mouse click, writing them to another folder tree that mirrors the original, only containing scaled down images. There are no commonly available monitors with resolutions > 2900x2900 and so in my original testing, I never ran across this problem.
But one of my beta testers "graduated" from a 6 MPixel digital SLR to a 12 MPixel digital SLR and found working with 3008x3008 images was a lot more convenient than working with 4288x4288 images. So he tried to use my program to perform this scaling. That's how he ran into the problem.
|
|
|
|
|