Outlook 2007: "The Text Formatting Command is not Available"

Hmm.

I was reading my mail this morning. Shutdown Outlook to do something else ( I do this, I don't like leaving Outlook running otherwise it eats your day ).

I run it up later on and notice that the reading pane isn't displaying the selected mail. I double click on a mail and Outlook tells me;

"Unable to display mail. The Text Formatting Command is not Available"

Weird! All I've done since I last ran Outlook is to do some stuff in Visual Studio. I didn't think that would have broken Outlook :-(

I do a bit of a search and the only KB article I can find is;

http://support.microsoft.com/kb/235244/en-us

which tells me to uninstall/reinstall IE but that seems a bit scary in that I have IE8 whereas this article was written around IE4 which feels like a very long time ago.

I opt to do a "Repair" on "Office Enterprise 2007" and see if that resolves anything for me.

And...it does. Or maybe it does. It asks me to reboot and I don't feel confident enough to ignore it so I let it reboot the box and when it comes back up I can read mail once again in Outlook. So, either the reboot fixed it or the repair fixed it but either way it's back and alive.


Filed Under: ,

WPF Pixel Shader Library on CodePlex

Via Jaime R, there's a whole set of transitions and effects to download up at CodePlex if you're on 3.5 Sp1.

Link


Filed Under: ,

WPF and Virtual Eath, Part 2

Following on from here, I thought I'd add a little bit of pushpin support to my basic Virtual Earth control for WPF.

Essentially, I added a new property to the control called PushPins and each one of those is just a tuple of;

{ Latitude, Longitude, Text }

to be placed on the map.

This means that from XAML I can create a set of pushpins in a declarative way as in;

      <ve:VirtualEarth
        x:Name="veControl"
        Grid.Column="1"
        ZoomLevel="{Binding Path=Value, ElementName=slidey}"
        Latitude="{Binding Path=Text, ElementName=txtLat}"
        Longitude="{Binding Path=Text, ElementName=txtLon}"
        MapStyle="{Binding Path=Text, ElementName=cmbMapStyle}">
        <ve:VirtualEarth.PushPins>
          <ve:PushPin
            Latitude="47.6"
            Longitude="-122.33"
            Text="Seattle 1" />
          <ve:PushPin
            Latitude="47.7"
            Longitude="-122.33"
            Text="Seattle 2" />
          <ve:PushPin
            Latitude="47.8"
            Longitude="-122.33"
            Text="Seattle 3" />
        </ve:VirtualEarth.PushPins>

      </ve:VirtualEarth>

or I could databind them but either way in code if I want to manipulate that collection I can just do something like;

veControl.PushPins.Remove(p);

or;

   PushPin p = new PushPin()
        {
          Latitude = double.Parse(txtAddLat.Text),
          Longitude = double.Parse(txtAddLon.Text),
          Text = txtAddName.Text
        };
        veControl.PushPins.Add(p);

and that seems to work reasonably well. I also added a lookup routine which will asynchronously go and look up a postcode and bring it back as a Lat/Lon which means I can now write code such as;

veControl.BeginLookupPostCode(txtPostcode.Text, Callback, txtPostcode.Text);

and I'll get a callback;

   void Callback(IAsyncResult result)
    {
      try
      {
        PostCodeLookupResult postCode = veControl.EndLookupPostCode(result);

        txtAddLat.Text = postCode.Latitude.ToString();
        txtAddLon.Text = postCode.Longitude.ToString();
      }
      catch (Exception e)
      {
        MessageBox.Show(e.Message);
      }
    }

which contains the Lat/Lon of the post-code that I looked up. What I haven't done is to implement INotifyPropertyChanged on a PushPin and then move the pin on the map if you change a property - I'd currently have to remove and re-add any pushpin that changed.

I added some support for PushPins into my little test harness which now looks like;

image

and allows me to basically manipulate the new functionality.

Once again, I've put the code up here for download.


Filed Under: , ,

WPF and Virtual Earth

WPF Version 3.5 Service Pack 1 has a new WebBrowser control as I talked about a little here;

http://channel9.msdn.com/posts/mtaulty/WPF-35-Sp1-WebBrowser-Control/

and some of the nice things about the control are;

  1. It can load HTML from a Stream or a string - i.e. you don't have to hit the web.
  2. You can call from the surrounding .NET code into script inside the control.
  3. You can call from script inside the control into the surrounding .NET code.

This seemed to be enough to form the basis of using the Virtual Earth control inside of WPF so I set about trying to build a control that did a very basic version of that.

The basic approach that I took is;

  1. WPF UserControl with dependency properties for Latitude, Longitude, ZoomLevel and MapStyle.
  2. Put an embedded HTML file inside the resources of my control's assembly which contains the HTML needed to load the Virtual Earth control along with the script needed to;
    1. Make it possible to set the Latitude, Longitude, ZoomLevel and MapStyle from my UserControl.
    2. Pass appropriate notifications back from the Virtual Earth control to my control.

That's pretty much it - I've not finished it yet by any means as I want to add some push-pin functionality and I'm sure there's bugs in this thing.

Along the way I did get a little bit foxed at one point because I want to be able to use my control in scenarios such as

      <ve:VirtualEarth
        x:Name="veControl"
        Grid.Column="1"
        ZoomLevel="{Binding Path=Value, ElementName=slidey}"
        Latitude="{Binding Path=Text, ElementName=txtLat}"
        Longitude="{Binding Path=Text, ElementName=txtLon}"
        MapStyle="{Binding Path=Text, ElementName=cmbMapStyle}" />

So, everything there is databound. Seems easy but the "problem" I got into was that WPF's databinding would start setting these properties and I would pass them through to the Virtual Earth control before it was ready to accept them and it would fail a lot.

So, I had to put a bit of a queue in between the WPF control and the Virtual Earth control where I queue up commands for the control if the control has not yet said that it is "ready".

Here's an example of the control in use in a simple test-harness;

image

And it's entirely declaratively data bound there.

I'm sure that it can relatively easily be "broken" if you play with it too much but I thought I'd share it.

Here's the solution for download - including the control and the test harness. I'll move this forward a little bit because I want to add the ability to search by post-code and add a few push-pins but I thought it was worth sharing.


Filed Under: , ,

UK Centre on Channel 9

We've started some tentative steps towards a UK area on Channel 9 which is up here;

http://channel9.msdn.com/UnitedKingdom/

Let me know if you've got great ideas around what should appear up there. If you're a community leader in the UK then you should see your events being advertised up there at the moment in the "resources" section.


Filed Under:

REMIX UK Sessions on the Web

My ( and everyone else's :-) ) sessions from REMIX UK are now live on the web for viewing up at;

http://www.microsoft.com/uk/remix08/agenda.aspx

I'm on Day 2 with my;

No Silverlight ( 2 ) Application Is An Island of Richness

Beyond Silverlight with Windows Presentation Foundation

sessions.

If I say so myself the WPF session feels a bit better than the Silverlight session as I was feeling less stuffed up with a cold at that point having "enthused" myself during the earlier session :-)


Filed Under: , ,

JavaScript makes me want to cry

I spent about 3 hours today trying to figure out why some little piece of script (in amongst some other masses of script) wasn't running. I think it ultimately came down to the difference between;

<script .....>

</script>

and

<script.... />

I know I'm a long way from being any good at Javascript so someone with experience would find these kinds of problems straight away but please tell me that this is not meant to be the future of software development where we effectively do #includes of some massive lump of code at runtime.

</rantOver>

As an aside, I think I've done this before :-)

As a second aside, it was ultimately the developer tools in IE8 that sorted it out for me so thanks to those :-)

Forcing 32-bit CLR Exes on a 64-bit Machine

This one really comes via Mike in that today we were both running the same application on our machines ( same machine spec ) and it was working for me but not for him.

We were foxed until he pointed out that he was running 64-bit ( which I stopped running a little while ago ).

This was an EXE that was using a bunch of .NET CLR assemblies plus a bunch of unmanaged assemblies which seemed to be failing to load.

So...as we remembered from here you can't have a mixed 32-bit/64-bit process on a 64-bit machine. It has to be all one or the other.

Problem is, if you compile for CLR then generally you choose "any platform" which means Mike's EXE was choosing to JIT its code as 64-bit but then it was trying to load the unmanaged DLLs which were 32-bit and, hence, failing.

Because we didn't have the source for this code, we solved the problem by running

corflags.exe /32BIT+

on the executable which changes the header to say to the CLR "I want to JIT 32-bit code please" as though the original builder of the software had selected x86 rather than "Any CPU" in Visual Studio.

This worked a treat in this specific instance - definitely one for me to remember and so I'm storing it here.


Filed Under:

WPF - Experimenting with Multi-Input Pixel Shaders

Whilst my day job continues on its ever-accelerating decline :-) I thought I'd entertain myself by experimenting with multi-input pixel shaders in WPF following on from the post I wrote over here.

Now, luckily for me Greg over here has already talked about it and it turns out to be not much of a stretch over what I did previously - you define a 2nd input for your shader of type brush and then you can sample from either input in order to produce the resultant effect.

I took my previously created "Swirl" effect and added a second brush to make a sort of "BlendAndSwirl" effect;

float factor : register(C0);
float blend : register(C1);

sampler2D input : register(S0);
sampler2D input2 : register(S1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
  float angle = -3.14;
  float yDist = uv.y - 0.5;
  float xDist = uv.x - 0.5;
  float dist = sqrt(xDist * xDist + yDist * yDist);
  angle *= dist * factor;

  float xN = cos(angle) * xDist - sin(angle) * yDist;
  float yN = sin(angle) * xDist + cos(angle) * yDist;
  uv.x = xN + 0.5;
  uv.y = yN + 0.5;
  float4 img1Colour = tex2D(input, uv); 
  float4 img2Colour = tex2D(input2, uv);
  img1Colour *= blend;
  img2Colour *= (1.0 - blend);
  img2Colour += img1Colour;
  return(img2Colour);
}

and then wrote the C# to go hand in hand with it;

  public class BlendSwirlEffect : ShaderEffect
  {
    static BlendSwirlEffect()
    {
      _pixelShader.UriSource = Global.MakePackUri("effect1.ps");
    }
    public BlendSwirlEffect()
    {
      this.PixelShader = _pixelShader;

      UpdateShaderValue(InputProperty);
      UpdateShaderValue(Input2Property);
      UpdateShaderValue(SwirlProperty);
    }
    public Brush Input
    {
      get { return (Brush)GetValue(InputProperty); }
      set { SetValue(InputProperty, value); }
    }

    public static readonly DependencyProperty InputProperty =
        ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BlendSwirlEffect), 0);

    public Brush Input2
    {
      get { return ((Brush)GetValue(Input2Property)); }
      set { SetValue(Input2Property, value); }
    }

    public static readonly DependencyProperty Input2Property =
      ShaderEffect.RegisterPixelShaderSamplerProperty("Input2", typeof(BlendSwirlEffect), 1);

    public double Swirl
    {
      get { return (double)GetValue(SwirlProperty); }
      set { SetValue(SwirlProperty, value); }
    }

    public static readonly DependencyProperty SwirlProperty =
        DependencyProperty.Register("Swirl", typeof(double), typeof(BlendSwirlEffect),
                new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0)));

    public double Blend
    {
      get { return (double)GetValue(BlendProperty); }
      set { SetValue(BlendProperty, value); }
    }

    public static readonly DependencyProperty BlendProperty =
        DependencyProperty.Register("Blend", typeof(double), typeof(BlendSwirlEffect),
                new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1)));

    private static PixelShader _pixelShader = new PixelShader();
  }

 

there's nothing too magical going on in here - we just have a 2nd brush to play with and sample and then I've got 2 factors to control the "level" of Blending of one picture with another and the "factor" applied to the Swirl.

I then built a little UI to use the effect;

  <Grid x:Name="mainGrid">
    <Grid.Resources>
      <ImageBrush
        x:Key="brush1"
        ImageSource="c:\windows\web\wallpaper\img1.jpg"
        Stretch="Fill" />
      <Storyboard
        x:Key="sbAnimate" Storyboard.TargetName="blendEffect" FillBehavior="HoldEnd">
        <DoubleAnimation
          Storyboard.TargetProperty="Blend"
          From="0"
          To="1" 
          BeginTime="00:00:00.5"
          Duration="00:00:00.5"/>
        <DoubleAnimation
          Storyboard.TargetProperty="Swirl"
          From="0"
          To="4" 
          Duration="00:00:01"/>
        <DoubleAnimation
          Storyboard.TargetProperty="Swirl"
          From="4"
          To="0"
          Duration="00:00:01"
          BeginTime="00:00:02"/>
      </Storyboard>
    </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition
        Height="4*" />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Image
      Source="c:\windows\web\wallpaper\img2.jpg"
      Stretch="Fill"
      Margin="10">
      <Image.Effect>
        <local:BlendSwirlEffect
          x:Name="blendEffect"
          Input2="{DynamicResource brush1}"
          Swirl="{Binding ElementName=swirlSlider,Path=Value}"
          Blend="{Binding ElementName=blendSlider,Path=Value}" />
      </Image.Effect>
    </Image>
    <StackPanel Grid.Row="1">
    <Grid 
      HorizontalAlignment="Stretch">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <StackPanel
        Margin="10">
        <Slider
          x:Name="blendSlider"
          Minimum="0"
          Maximum="1"
          MinWidth="192"
          Margin="5"/>
        <TextBlock
          FontSize="14"
          Text="Blend"
          TextAlignment="Center" />
      </StackPanel>
      <StackPanel
        Margin="10"
        Grid.Column="1">
        <Slider
          x:Name="swirlSlider"
          Minimum="0"
          Maximum="4"
          MinWidth="192"
          Margin="5"/>
        <TextBlock
        FontSize="14"
        Text="Swirl"
        TextAlignment="Center" />
      </StackPanel>      
    </Grid>
      <Button
        FontSize="14"
        Content="Animate"
        Click="OnAnimate" 
        MinHeight="48"
        MinWidth="192"
        HorizontalAlignment="Center"/>
    </StackPanel>
  </Grid>

 

Which just defines an Image that's using the BlendSwirlEffect and a second image brush that it's using as the 2nd image to sample in the pixel shader ( Input2 in the code and the XAML ).

This gives a UI like thi;s

image

where I can then go and blend/swirl a little;

image

and I stuck a little animation on there that animates both properties at the same time. Here's the project code if you want to play with it - note that to compile it you'll need the directX SDK so I've included the binary files in the project in case you just want to run it.


Filed Under: ,

WPF DataGrid and Hiding Columns

Looking for advice here :-) I find that in the WPF/Silverlight DataGrids there's this option which is really useful;

AutoGenerateColumns="true/false"

but I generally don't want either true or false. What I seem to want is;

"Autogenerate all of them but I don't want to display columns A,B,C"

and I'm not sure how I do that. I ended up deriving my own DataGrid just to try and make that work as in;

  [ContentProperty("Name")]
  public class HiddenColumn
  {
    public HiddenColumn()
    {
    }
    public string Name { get; set; }
  }
  class HideableDataGrid : DataGrid
  {
    public HideableDataGrid()
    {
      HiddenColumns = new List<HiddenColumn>();
      this.AutoGeneratingColumn += OnGeneratingColumn;
    }

    void OnGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
      if (HiddenColumns != null)
      {
        e.Cancel = HiddenColumns.Exists(hc => string.Compare(e.PropertyName, hc.Name, true) == 0);
      }
    }
    public List<HiddenColumn> HiddenColumns { get; set; }
  }

and then use that as in;

 <local:HideableDataGrid
      x:Name="ordersGrid"
      Grid.Row="2"
      Style="{StaticResource myStyle}"
      AutoGenerateColumns="True"
      DataContext="{Binding ElementName=customersGrid,Path=SelectedValue.Orders}"
      ItemsSource="{Binding}"
      InitializingNewItem="OnOrdersGridRowInsert">
      <local:HideableDataGrid.HiddenColumns>
        <local:HiddenColumn>CustomerID</local:HiddenColumn>
        <local:HiddenColumn>CompanyName</local:HiddenColumn>
        <local:HiddenColumn>OrderID</local:HiddenColumn>
      </local:HideableDataGrid.HiddenColumns>
    </local:HideableDataGrid>

but this can't be the right thing to do here? ( + the naming I've given the derived class is horrible ).


Filed Under: ,
More Posts Next page »