Click here to Skip to main content
       

Silverlight / WPF

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AnswerRe: mmmvpRichard MacCutchan28 Dec '12 - 5:59 
"mm" is not a very good title for a question; try putting something meaningful. As to Expression Blend, follow the link I gave you in your other question and find it in MSDN.
One of these days I'm going to think of a really clever signature.

GeneralsiverlightmemberAishwarya aishu28 Dec '12 - 0:42 
what is the use of silverlight??? how do we use that in asp.net???? Smile | :)    Smile | :)    Smile | :)    Smile | :)
 
aishu
GeneralRe: siverlightmvpRichard MacCutchan28 Dec '12 - 5:57 
Start here[^]. You could also look at these articles[^].
One of these days I'm going to think of a really clever signature.

QuestionDataTrigger bind to a Propertymembermbv80023 Dec '12 - 17:01 
I am trying to change the appearance of a control when the value of a property changes. I am using the XAML and C# code below, but nothing happens when I click on the button that changes the value of the Property myProperty, except when I first run the application. Any suggestions?
 

<Window x:Class="WpfApplication3.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>
<Button Height="34" HorizontalAlignment="Left" x:Name="toggleBroadcast" VerticalAlignment="Top" Width="133" Margin="180,0,0,0">
<Button.Style>
  <Style x:Name="bb" TargetType="{x:Type Button}">
   <Setter Property="Content" Value="Original Content"/>
    <Style.Triggers>
      <DataTrigger Binding="{Binding Path=myProperty}" Value="true">
        <Setter Property="Content" Value="IS TRUE"/>
      </DataTrigger>
      <DataTrigger Binding="{Binding Path=myProperty}" Value="false">
          <Setter Property="Content" Value="IS FALSE"/>
      </DataTrigger>
     </Style.Triggers>
                    
                </Style>
            </Button.Style>
         </Button>
        <Button Content="Click on This Button" HorizontalAlignment="Left" Width="158" Click="Button_Click_1" Height="34" VerticalAlignment="Top"/>
   </Grid>
</Window>
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
 
namespace WpfApplication3
{
    public partial class MainWindow : Window
    {
        Boolean _Check = false;
        public MainWindow()
        {
            DataContext = this;
            InitializeComponent();
        }
        public Boolean check
        {
            get
            {
                return _Check;
            }
        }
 
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            _Check = !_Check;
        }
    }
}

AnswerRe: DataTrigger bind to a PropertyprotectorPete O'Hanlon23 Dec '12 - 19:17 
There are a couple of things wrong with your code here. The first thing is that you don't have to supply both true and false DataTrigger elements. Add one of those triggers as the default content. When the bool value goes to the default value, the style trigger is removed.
 
Now, as to why you aren't seeing the value change. Even though you are changing the value, you aren't telling the XAML that the value has changed. Make this class implement INotifyPropertyChanged and have your code raise the PropertyChanged event when the vale changes. This raises the change notification.
 
Oh, and you aren't binding to check in your example. You are binding to myProperty.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

AnswerRe: DataTrigger bind to a PropertymentorWayne Gaylard23 Dec '12 - 19:39 
First of all, you have not done any binding to your Check Property, binding to myProperty will not help you at all. You need to change your binding to bind to the Check property. Secondly for bindings to react to changes in the bound property you need to implement the INotifyPropertyChanged[^] interface in you viewmodel/code behind. Try this code :
 
<Grid>
        <Button Height="34" HorizontalAlignment="Left" x:Name="toggleBroadcast" VerticalAlignment="Top" Width="133" Margin="180,0,0,0">
            <Button.Style>
                <Style x:Name="bb" TargetType="{x:Type Button}">
                    <Setter Property="Content" Value="Original Content" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Check}" Value="true">
                            <Setter Property="Content" Value="IS TRUE" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Check}" Value="false">
                            <Setter Property="Content" Value="IS FALSE" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
        <Button Content="Click on This Button" HorizontalAlignment="Left" Width="158" Click="Button_Click_1" Height="34" VerticalAlignment="Top" />
    </Grid>
 
public partial class MainWindow : Window,INotifyPropertyChanged
    {
        Boolean _check = false;
 
        public MainWindow()
        {
            DataContext = this;
            InitializeComponent();
        }
 
        public Boolean Check
        {
            get
            {
                return _check;
            }
            set
            {
                if (_check != value)
                {
                    _check = value;
                    OnPropertyChanged("Check");
                }
            }
        }
 
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Check = !Check;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

QuestionWPF Adorner IssuesmvpJohn Simmons / outlaw programmer17 Dec '12 - 10:52 
We have a scene designer in our app that allows the user to add elements and resize, rotate, and position them.
 
When the user tries to resize to make the adorned element shorter, the adorner reaches a certain size and stops getting smaller (both vertically and/or horizontally), but the adorned element continues to get smaller.
 
I've looked and looked, but can't find anything that resembles a minimum height or width property.
 
There's a LOT of code associated with this problem (the adorner class is 525 lines all by itself, and then there's the xaml for the thumbs), so I'm not real fond of the idea of posting ALL of the code at once unless it's absolutely necessary.
 
Can anyone provide guidance?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

AnswerRe: WPF Adorner IssuesmemberSledgeHammer0118 Dec '12 - 4:49 
There is a MinHeight and MinWidth, but it should be undefined by default. This is one of those "look around at random sh*t until you stumble across the issue" type problems Smile | :) . I'd start at figuring out what size the adorner stops working at. Is it the same for height and width? Is it some arbitrary number like 47.488484 or is it something system metric-y like 32? Once you have figured out the height and width that the adorner stops shrinking at, I'd rack your brain and look through the code to try to figure out where those numbers are coming from. I'd also put diagnostic messages in all the adorner layout calculation functions to see what sizes & points are coming in and what size & points you are returning and what you are doing with your visuals. Also check that the mouse messages are being processed as expected.
GeneralRe: WPF Adorner IssuesmvpJohn Simmons / outlaw programmer20 Dec '12 - 9:09 
Actually, it's got something to do with RenderSize on the adorned element. I thought I had it figured out today when I overrode OnRender, and set the render size in there, but when I do something else (like drag, resize, or rotate), the RenderSize goes back to its original value, but then immediately reverts to it's set size (because I set it in OnRender). Furthermore, the rotation code STILL uses the (wrong) render size values to set the center of the rotate transform.
 
I hate WPF. If you think it would be worth it, I could post my adorner code (but like I said before, there's a LOT of it).
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

GeneralRe: WPF Adorner IssuesmemberSledgeHammer0121 Dec '12 - 4:50 
You usually just override the MeasureOverride and the ArrangeOverride methods. Those two methods have to return the correct sizes and arrange everything properly for the adorners to work right.
QuestionSilverlight Dynamic indexed binding [modified]memberMember 934221816 Dec '12 - 18:02 
I have a requirement where I am using a datagrid and the number of columns will not be known until runtime. I found the following article and was able to get it working.
 
http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/
 
However this solution uses the XamlReader and creates a datatemplate in the code behind. I am not entirely happy with this solution. Is there another way that I can achieve the same result without using the XamlReader. Essentially im trying to achieve something like this
 
CellTemp.Append(String.Format("<TextBlock Text='{{Binding Periods[{0}].{1}}}'/>", index, propertyName));
but instead of using the XamlReader create this binding in in xaml.

modified 17 Dec '12 - 0:34.

QuestionThird Party ControlsmemberKevin Marois11 Dec '12 - 7:22 
I'm researching control packages for WPF.
 
I'm considering Telerik, XCeed, and DevExpress.
 
As far as Telerik goes, I have used them before and I like them a lot. Good controls with excellent support.
 
Anyone used XCeed, or DevExpress?
 
Please don't suggest Infragistics. They flat out suck and I'll never use them again.
 
Thanks
If it's not broken, fix it until it is

AnswerRe: Third Party ControlsmemberMycroft Holmes11 Dec '12 - 12:06 
I'll be astonished if you can get a balanced response to that question, 1 lousy experience will ruin some ones opinion of a toolset. A good experience and deep knowledge will do the opposite.
 
We use Telerik and are very pleased to have changed from Infragistics.
Never underestimate the power of human stupidity
RAH

AnswerRe: Third Party ControlsprotectorPete O'Hanlon11 Dec '12 - 12:43 
Take a look at Mindscape. I use them a lot and am really impressed by them.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Third Party ControlsmemberKevin Marois12 Dec '12 - 8:28 
Thanks, they look nice. And their site says their controls are geared towards MVVM, which is nice
If it's not broken, fix it until it is

GeneralRe: Third Party ControlsprotectorPete O'Hanlon12 Dec '12 - 8:29 
I can't praise them enough. The way I view it is, would I use this control if I had to pay for it myself? And I did.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Third Party ControlsmemberKevin Marois12 Dec '12 - 8:30 
Good, thanks! +5
If it's not broken, fix it until it is

GeneralRe: Third Party ControlsmemberMycroft Holmes12 Dec '12 - 12:02 
High praise indeed.
Never underestimate the power of human stupidity
RAH

QuestionHow can I Bind a DataTemplate Slider definition to the Code behind?membermaycockt10 Dec '12 - 5:24 
I have a DataTemplate which, when referenced, displays a Slider Bar. The setup of the slider is dependant on data passed to the Form from the calling class. The XAML for the config looks like this.
 
<pre lang="xml">
<Window.Resources>
      <DataTemplate   DataType="{x:Type ContentControl}" x:Key="TextBoxTemplate">
            <TextBox Text="{Binding ElementName=MyWindow, Path=m_csValue}" Height="23"/>
      </DataTemplate>
      <DataTemplate DataType="{x:Type ContentControl}" x:Key="SliderTemplate">
            <Slider Name="sli" Value="{Binding ElementName = MyWindow, Path=sli}" ValueChanged="OnSliderValueChanged" IsSnapToTickEnabled="True" Margin="5" />
      </DataTemplate>
      <Style TargetType="{x:Type ContentControl}" x:Key="DisplayValues">
            <Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
            <Style.Triggers>
                  <DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Text}">
                        <Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
                  </DataTrigger>
                  <DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Slider}">
                        <Setter Property="ContentTemplate" Value="{StaticResource SliderTemplate}" />
               </DataTrigger>
            </Style.Triggers>
      </Style>
</Window.Resources>
 
<Grid Width="267">
      <StackPanel Margin="0,37,0,133" Height="123">
            <TextBlock Height="23" Name="textBlock1" Text="TextBlock" HorizontalAlignment="Center" VerticalAlignment="Center"/>
      </StackPanel>           
 
      <ContentControl Style="{StaticResource DisplayValues}" Margin="12,12,12,158" />
</Grid>
</pre>
 
In my Code Behind I set up the Max, Min, Tick Frequency and Value when the Form is created.
When the Slider bar is updated i find that the slider in the code behind is not bound to the slider on display, and so I'm not updating the value of the object I wish to update.
How can I ensure that the slider created in the XAML is bound to the slider in the code behind?
 
Regards
 
Tony
AnswerRe: How can I Bind a DataTemplate Slider definition to the Code behind?memberAlisaunder10 Dec '12 - 13:52 
In my project I have this xaml code for my slider
 
            <StatusBarItem Grid.Column="5" Padding="4,0,15,0">
                <StackPanel x:Name="StatusBarSlider" Orientation="Horizontal">
                    <TextBlock x:Name="StatusBarItem"
                               Margin="0,1,0,1"
                               Foreground="{Binding Foreground,
                                                    ElementName=navigationPane}"
                               Padding="6,0,6,0"
                               Text="{Binding Value,
                                              ConverterParameter=%,
                                              Converter={StaticResource PercentageConverter},
                                              ElementName=scaleSlider}" />
 
                    <RepeatButton Margin="1,0,1,0"
                                  CommandTarget="{Binding ElementName=scaleSlider}"
                                  ribbon:ScreenTipService.ScreenTipHeader="Zoom Out"
                                  Style="{StaticResource {x:Static themes:SharedResourceKeys.StatusBarEmbeddedSliderDecreaseButtonBaseStyleKey}}" />
                    <Slider x:Name="scaleSlider"
                            Width="100"
                            VerticalAlignment="Center"
                            IsSnapToTickEnabled="True"
                            LargeChange="0.5"
                            Maximum="2.0"
                            Minimum="0.5"
                            ribbon:ScreenTipService.ScreenTipHeader="Zoom"
                            SmallChange="0.1"
                            TickFrequency="0.1"
                            Value="1.0" />
                    <RepeatButton Margin="1,0,1,0"
                                  CommandTarget="{Binding ElementName=scaleSlider}"
                                  ribbon:ScreenTipService.ScreenTipHeader="Zoom In"
                                  Style="{StaticResource {x:Static themes:SharedResourceKeys.StatusBarEmbeddedSliderIncreaseButtonBaseStyleKey}}" />
                </StackPanel>
            </StatusBarItem>
 
My code Behind this is
 
// preparing tab content slider transformation
                    ScaleTransform scaleTransform = new ScaleTransform();
                    Binding scaleXBinding = new Binding("Value");
                    scaleXBinding.Source = scaleSlider;
                    Binding scaleYBinding = new Binding("Value");
                    scaleYBinding.Source = scaleSlider;
 
                    // binding main form slider to tab content
                    BindingOperations.SetBinding(scaleTransform,
                                                 ScaleTransform.ScaleXProperty,
                                                 scaleXBinding);
                    BindingOperations.SetBinding(scaleTransform,
                                                 ScaleTransform.ScaleYProperty,
                                                 scaleYBinding);
 
and since I am scaling something being displayed inside a tab I use this
 
// adding content to new tab                    
                    newTab.Content = Contact2;
 
                    Contact2.contentContainer.LayoutTransform = scaleTransform;
 
This binds the slider control to the contents of my contacts. Hope this helps.Thumbs Up | :thumbsup:
GeneralRe: How can I Bind a DataTemplate Slider definition to the Code behind?membermaycockt14 Dec '12 - 1:18 
Hi,
 
Thanks for your response, I've only just managed to pick this up.
I've looked at your code sample, many thanks.
 
The issue that I'm seeing is that using the "Name" declared for the Slider, I cannot use it in my CodeBehind without declaring an independent Slider object - which creates and new object and doesnt bind to the declared Slider in the XAML.
 
As the Slider is named and delcared in a the <Windows.Resources> section, and as part of a <DataTemplate>, do I need to reference by more than just the object name, e.g. would I need to call it something like someItem.sli as opposed to just sli?
 
Regards
 
Tony
QuestionHow does one define IOleServiceProvider in a C# WPF application?memberXarzu10 Dec '12 - 3:54 
How does one define IOleServiceProvider in a C# WPF application?
 
I was told that it was automatically recogized if I downloaded and installed the visual studio SDK.   Is there some extra step I am missing?
http://i67.photobucket.com/albums/h292/Athono/programming/12-9-2012.png
 
IOleServiceProvider is from the Namespace Microsoft.TeamFoundation...
But I cannot declare this:
 
http://i67.photobucket.com/albums/h292/Athono/programming/12-9-2012-2.png
AnswerRe: How does one define IOleServiceProvider in a C# WPF application?protectorPete O'Hanlon10 Dec '12 - 4:08 
Are you trying to use this from a Visual Studio addin? That's what the VS SDK IOleServiceProvider is present in. Here's[^] an example using it.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

QuestionSetting icons based on Region/city name?!memberradkrish9 Dec '12 - 19:43 
<pre>
<HierarchicalDataTemplate DataType="{x:Type local:RegionViewModel}" ItemsSource="{Binding Children}">
          <StackPanel Orientation="Horizontal">
            <Image Width="16" Height="16" Margin="3,0" Source="Images\Region.png" />
            <TextBlock Text="{Binding RegionName}" />
          </StackPanel>
</HierarchicalDataTemplate>
</pre>
 
Hi in the above data template whenever the type is a region, it says to use a particular icon.
But I want to chose icon based on the name of the region! Could you please let me know How I do this please?
Regards
RK

AnswerRe: Setting icons based on Region/city name?!mvpAbhinav S9 Dec '12 - 20:12 
I guess you should use vector paths rather than icon images as dynamic images.
 
You could try the following resources -
Animation Along a Path for Silverlight[^]
http://msdn.microsoft.com/en-us/library/system.windows.shapes.path%28v=vs.95%29.aspx[^]
WP7.5 Apps - XKCD | Calvin | SMBC | Sound Meter | Speed Dial

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid