4

I have a project which has several UI culture references like this:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel Orientation="Horizontal" Grid.Column="1">
        <TextBlock Text="{Binding MyData, StringFormat={}{0:C2}, ConverterCulture={x:Static sysglb:CultureInfo.CurrentUICulture}}"  />
    </StackPanel>
</Grid>

In code behind, I have a simple implementation:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        MyData = 10;
    }

    public int MyData { get; set; }
}

In App_Startup, I have initialized the CurrentUICulture:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

When I open any such UI in designer, I receive 'Invalid Markup' with error:

The member "CurrentUICulture" is not recognized or is not accessible.

Any idea why this basic use case will not work in Xaml designer for Visual Studio 2015 RC? I have tried options mentioned in an earlier post, but that does not work (Visual studio 2012 XAML designer invalid markup)

Earlier, when loading the designer, we could see the controls and UI without problems in Visual Studio 2010, 2012 and 2013. We decided to try out Visual Studio 2015 RC, but it appears that this is broken now.

Community
  • 1
  • 1
nkanani
  • 548
  • 1
  • 6
  • 7
  • Try this one : System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB"); – Gul Ershad Jun 08 '15 at 13:15
  • @GulMdErshad Tried it, doesn't work. The problem is specific to VS 2015 RC... – nkanani Jun 09 '15 at 07:59
  • Remotely related though, there is another issue which was answered: http://stackoverflow.com/questions/29994558/visual-studio-2015-c-sharp-xaml-designer-doesnt-load?rq=1 – nkanani Jun 25 '15 at 10:25
  • Same problem in VS2015 RTM. I found changing the target framework to 4.6 fixes it, but I don't want that. – avenmore Aug 19 '15 at 13:37

1 Answers1

1

Further to my comment that changing the target framework to .NET Framework 4.6 solves the problem, I think this is a bug in the VS2015 XAML editor, something to do with changes to the CultureInfo.CurrentUICulture Property being now read-write.

As a work-around I changed the app startup to

CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-GB");

and the XAML to

<TextBlock Text="{Binding MyData, StringFormat={}{0:C2}, ConverterCulture={x:Static sysglb:CultureInfo.DefaultThreadCurrentUICulture}}"/>

and it seems happy with that.

avenmore
  • 2,809
  • 3
  • 33
  • 34
  • 1
    Something else that seems to have worked (changing the framework is not an option in my case), is to change the build configuration. Mine was set to AnyCPU, so I change it to 64 bit and back to AnyCPU again. It rebuilt the obj folder and all is working again. Possibly, deleting that folder would have served the same purpose. – maplemale Jul 05 '16 at 22:22