|
I have a style defined for a ListViewItem. In this style, there is a MultiDataTrigger. One of the conditions uses RelativeSource to get to a property in the ListView (RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}).
The trigger is working correctly, just as I expect, so I know all the syntax and everything is defined correctly.
HOWEVER, when you scroll a ListView and the ListViewItem goes off screen, it gets removed from the visual tree. This results in a lot of errors:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ListView', AncestorLevel='1''. BindingExpression:Path=SomeDP; DataItem=null; target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
I've tried everything I know of to get rid of them:
1) Tried adding a FallbackValue to the binding. This solves the error messages on XP, but does not work on Windows 7??? .NET 4.0 on both OSes.
2) Tried running the value through a dummy converter. This has gotten rid of error messages in the past, but not this time.
3) Tried setting the PresentationTraceSources.TraceLevel="None" AP on the condition. No effect.
Any other way to solve this?
|
|
|
|
|
I believe that a ListView uses a VirtualizingStackPanel for it's ItemsPanel and that the IsVirtualizing property defaults to true. Try setting it to false if you don't need your listview to hold many items. Either that or try using a regular StackPanel for the ItemsPanel.
while (e) { Coyote(); }
|
|
|
|
|
Definitely don't want to turn off virtualization. That eats a lot of memory. If I have 200 items, it adds around 50MB.
|
|
|
|
|
Hello!
i have a problem with the resource dictionaries in silverlight,
control styles is using the colors in my colors resource.
but when i do this i get runtime error when i load the silverlight app in my browser:
Cannot find a Resource with the Name/Key OfficeBlue [Line: 10 Position: 44]
i have confirmed that the key name exists in colors.xaml
this is from my app.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml" />
<ResourceDictionary Source="Navigate/Control styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
How do i use colors.xaml resource in my control style?
Thanks!
modified on Tuesday, April 19, 2011 2:25 AM
|
|
|
|
|
It is unable to find the Resource file. Give a proper path there. A typical resource dictionary path will look as below:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ASSEMBLY_NAME;component/FILENAME.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Note: Change the name of the ASSEMBLY_NAME in the above code. Also change the FILENAME. If it is in a different sub directory, say "Themes", it will look as below:
<ResourceDictionary Source="/ASSEMBLY_NAME;component/Themes/FILENAME.xaml"/>
Hope this will answer your query. Mark as Answer, if this helps.
Regards - Kunal Chowdhury | Microsoft MVP (Silverlight) | CodeProject MVP | Software Engineer
|
|
|
|
|
Hello,
While exporting the telerik chart to PNG image format, I received below mentioned error message.
<b>dialogs must be user-initiated.</b>
Perhaps the image is saved successfully. Can any one can help me why I got this type of error message?
Here is my code:
try
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = ".png";
dialog.Filter = "Portable Network Graphics (*.png)|*.png";
bool? showDialog = dialog.ShowDialog();
if (showDialog == true)
{
Stream fileStream = dialog.OpenFile();
MainChart.ExportToImage(fileStream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());
fileStream.Close();
}
}
|
|
|
|
|
Where are you calling this code from? Silverlight expects the SaveFileDialog to be instantiated from a user initiated event (such as responding to a Button.Click).
|
|
|
|
|
Hello,
Thanks for the response. I am calling this method in the button click event and instantiated the SaveFileDialog in the same. Still got the error.
Thanks...
|
|
|
|
|
This[^] might help/
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi ,
I have a WPF - window, contains a StackPanel (designed in xmal, where height and width are Auto = 0). In code reading an image folder and adding the files to stackPanel. While adding files to image control, created a border object and intern created the image object and fina tlly adding the border to stackpanel.
Now when i try to resize the window, the stackpanel stays same size , as the image control width and hight are fixed thou the stackpanel is auto size.
below is the code snip ,
//after reading the image files, add it to stack panel
foreach (string strFile in ArrStrFiles)
{
// display the file names here
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = new Uri(strFile);
bi.EndInit();
Image img = new Image();
img.Source = bi;
img.Width = 170;
img.Height = stkPanl.ActualHeight;
img.Stretch = Stretch.Fill;
img.HorizontalAlignment = HorizontalAlignment.Stretch;
img.VerticalAlignment = VerticalAlignment.Stretch;
Border border = new Border();
border.Background = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(5);
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.Child = img;
stkPanl.Children.Add(border);
}
xmal :
<window ...="">
<grid>
<local:scrollviewerex x:name="scrollViewerEx" margin="92.664,0,92.349,7.137" verticalscrollbarvisibility="Hidden"
="" horizontalscrollbarvisibility="Hidden" verticalalignment="Bottom" background="Black" rendertransformorigin="0.5,0.5">
<local:scrollviewerex.rendertransform>
<transformgroup>
<scaletransform="">
<skewtransform>
<rotatetransform angle="360.216">
<translatetransform>
<stackpanel x:name="stkPanl" background="Black" orientation="Horizontal" rendertransformorigin="0.5,0.5">
Plz let me know how we can resize the stackPanel when the image is added thru code.
thanks
|
|
|
|
|
Xmal Part missed :
<window> ..
<grid>
<local:scrollviewerex x:name="scrollViewerEx" margin="92.664,0,92.349,7.137" verticalscrollbarvisibility="Hidden"
="" horizontalscrollbarvisibility="Hidden" verticalalignment="Bottom" background="Black" rendertransformorigin="0.5,0.5">
<local:scrollviewerex.rendertransform>
<transformgroup>
<scaletransform>
<skewtransform>
<rotatetransform angle="360.216">
<translatetransform>
<stackpanel x:name="stkPanl" background="Black" orientation="Horizontal" rendertransformorigin="0.5,0.5">
|
|
|
|
|
Hi,
Can anyone tell me how to check the duplicate data is present in listbox itemtemplate..
i have listbox, where i need to check whether the data enterred by the user in textbox is duplicate or not, how to do it..
my code is like this..
<ListBox x:Name="lbDirectiveList" MaxHeight="200" SelectionChanged="lbDirectiveList_SelectionChanged" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=DirectiveName}" Grid.Column="0" FontWeight="Bold" MinWidth="180"/>
<TextBlock Text=" - " Grid.Column="1"/>
<TextBlock Grid.Column="2" Text="{Binding Path=Descr }" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ObservableCollection<Directive> listdata=new ObservableCollection<Directive>();
class Directive
{
public string DirectiveName { get; set; }
public string Descr { get; set; }
}
Directive lstdir=new Directive {DirectiveName=txt1.Text.Trim(),Descr=txt2.Text.Trim()};
void Add(object sender,RoutedEventArgs e)
{
if(!listdata.Contains(lstdir))
{MessageBox.Show("Insert");}
else MessageBox.Show("Duplicate Data");
}
it is taking the duplicate value, after using the above code...
so any help on this...
|
|
|
|
|
In the code where you bind the property of the textbox, write some code to check if if the text box value is already contained within the collection that binds to the listbox. You can then handle the duplicate as you like.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
hi, i have used the code like the way u said, still its not running the code inside it(if Condition)...
Directive lstdir = new Directive { DirectiveName = txtDirectiveName.Text.Trim(), DirectiveDescription = txtDirectiveDescription.Text.Trim() };
if (txtDirectiveName.Text != lstdir.DirectiveName && txtDirectiveDescription.Text != lstdir.DirectiveDescription)
{
MessageBox.Show("Execute");
}
else MessageBox.Show("Duplicate Data")
|
|
|
|
|
Hello,
I have a UserControl that exposes a Selection property:
public partial class FeatureSelectionControl : UserControl
{
public string[] Selection
{
get { return (string[])GetValue(SelectionProperty); }
set { SetValue(SelectionProperty, value); }
}
public static readonly DependencyProperty SelectionProperty =
DependencyProperty.Register("Selection", typeof(string[]), typeof(FeatureSelectionControl), new UIPropertyMetadata(new string[] { }));
I want to use it in a window and bind the control's property to one of the window's properties:
<Window Name="Window" ...>
<local:FeatureSelectionControl Selection="{Binding ElementName=Window,Path=CustomerGroups}" ...>
</local:FeatureSelectionControl>
Code behind:
public partial class WindowCounterpartyGroupRiskReview : Window
{
public WindowCounterpartyGroupRiskReview()
{
CustomerGroups = new string[] { };
InitializeComponent();
}
public string[] CustomerGroups { get; set; }
This crashes with a "first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll Additional information: Object reference not set to an instance of an object". STack trace is:
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(System.Windows.Markup.MarkupExtension markupExtension = null, object obj = {System.Windows.Markup.BamlCollectionHolder}, object member = null) + 0x52 bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadPropertyArrayEndRecord() + 0x5f bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadRecord(System.Windows.Markup.BamlRecord bamlRecord) + 0x636 bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.Read(bool singleRecord = false) + 0x1c bytes
PresentationFramework.dll!System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() + 0xc9 bytes
PresentationFramework.dll!System.Windows.Markup.TreeBuilder.Parse() + 0xf bytes
PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream) + 0xc7 bytes
PresentationFramework.dll!System.Windows.Application.LoadComponent(object component, System.Uri resourceLocator) + 0x16e bytes
> CRRT.exe!CRRT.WindowCounterpartyGroupRiskReview.InitializeComponent() Line 1 + 0xb bytes C#
However, when I change my code and make the property a mere string, I don't get an exception and everything works as expected.
Any idea ?
|
|
|
|
|
Ok I found the solution here: use a List<string> instead of a string[].
|
|
|
|
|
Hello,
I'm having some difficulty retrieving JSON formatted data returned from a remote server. I'm using Silverlight 4 in VS 2010. My code is as follows:
byte[] response = new byte[32768];
SocketAsyncEventArgs e = new SocketAsyncEventArgs();
e.SetBuffer(response, 0, response.Length);
soc.ReceiveAsync(e);
string data = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred).Trim(new char[] { '\0' });
If I uncomment the call to Sleep for 4 or 5 seconds, then my string variable "data" populates consistently. However, if I don't Sleep, then after a few times of receiving updates, the variable "data" is consistently empty (although there is data in the buffer). Basically, I have to slow the whole process down in order to get my updates. That's not an acceptable solution though, as I'm dealing with market data which needs to be processed in real-time.
Incidentally, nearly identical code works without the call to Sleep in a console app I wrote against the same remote server. In that case, the following works perfectly:
byte[] snapBytes = new byte[32768];
soc.Receive(snapBytes);
String data = Encoding.ASCII.GetString(snapBytes).Trim(new char[] { '\0' });
Thanks in advance for any thoughts or ideas.
|
|
|
|
|
Well, yeah...
Do you understand what the "Async" in "ReceiveAsync" is supposed to do? Its an asynchronous function meaning its non blocking. So when you call soc.ReceiveAsync() it IMMEDIATELY goes to the next line and the buffer will be filled to a random length depending on millions of things.
This is used so you don't hang your GUI and don't need to handle multi-threading yourself.
You need to wait til the call is *really* done. For instance, by subscribing to the SocketAsyncEventArgs.Completed event .
|
|
|
|
|
Hello,
Anyone can tell me advantages using PRISM in Silverlight.
And Which design pattern is suitable for PRISM....Its MVVM?
Thanks & Regards...
|
|
|
|
|
|
Code Project author and Prism team member Karl Shifflett has literally written the book on Prism development. Check out his blog[^], and order the book.
|
|
|
|
|
MVVM does complement Prism.
Prism give you an opportunity to work in a more decoupled UI / code environment while giving you necessary framework features to call these framework features.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
I have just started learning WPF and exploring more on WPF controls.
Can any one help how to display popup? I have used TextBlock under popup control as below :
<pre> <Popup StaysOpen="True">
<TextBlock Name="txtBlock1">
This is simple PopUp in WPF..
</TextBlock>
</Popup></pre>
But how to trigger this popup?
Thanks and regards,
Rahul Chitte
|
|
|
|
|
Popups are shown with the IsOpen method.
|
|
|
|
|
Two ways:
1) Give it a name (The Popup itself, not just the TextBlock), and open it in the code-behind
2) (The preferred method) Bind the Popup's IsOpen property to something else, such as a toggle button or a boolean field on your underlying model.
|
|
|
|